...

View Full Version : Code (function call) not working in 2nd example



musher
09-02-2006, 11:21 PM
I was trying to clean up code on a page and changed Test 1 to Test 2 and it quit working.
Why does Test 1 work, but Test 2 does not (select box does not show up on test 2)?
logic (well to me any way) I see these both as echo-ing the function results



// Test 1
$var_field_name="emailer";
echo '<tr><td class="'.$parm_emailer_class.'">Test 1: </td><td>' . "\n";
echo YesNo_selection($hold_emailer, $var_field_name).'</td></tr>' . "\n";

// Test 2
$var_field_name="emailer";
echo '<tr><td class="'.$parm_emailer_class.'">Test 2: </td><td>' . YesNo_selection($hold_emailer, $var_field_name) . '</td></tr>' . "\n";
Here's Function:


// Display of Yes-No selection with DROP DOWN BOXES
function YesNo_selection($fvar_YesNo, $var_field_name) {
echo '<select class="text_update" name="'.$var_field_name.'">';
echo '<option value=""'; if (!(strcmp("", $fvar_YesNo))) {echo "SELECTED";} echo '>Select Yes or No</option>';
echo '<option value="1"'; if (!(strcmp("1", $fvar_YesNo))) {echo "SELECTED";} echo '>YES</option>';
echo '<option value="0"'; if (!(strcmp("0", $fvar_YesNo))) {echo "SELECTED";} echo '>NO</option>';
echo '</select>';
}

Fumigator
09-03-2006, 12:17 AM
What does "page source" look like on the processed page?

mic2100
09-03-2006, 12:32 AM
maybe it as sumthing to do with the way your function operates, instead of returning a value and using the echo on that.



// Test 1
$var_field_name="emailer";
$var_yesno_selection = YesNo_selection($hold_emailer, $var_field_name);
echo '<tr><td class="'.$parm_emailer_class.'">Test 1: </td><td>' . "\n";
echo $var_yesno_selection.'</td></tr>' . "\n";

// Test 2
$var_field_name="emailer";
$var_yesno_selection = YesNo_selection($hold_emailer, $var_field_name);
echo '<tr><td class="'.$parm_emailer_class.'">Test 2: </td><td>' . $var_yesno_selection . '</td></tr>' . "\n";



and the modified function is...



// Display of Yes-No selection with DROP DOWN BOXES
function YesNo_selection($fvar_YesNo, $var_field_name) {
$ynreturn .= '<select class="text_update" name="'.$var_field_name.'">';
$ynreturn .= '<option value=""';
if (!(strcmp("", $fvar_YesNo)))
{
$ynreturn .= "SELECTED";
}
$ynreturn .= '>Select Yes or No</option>';
$ynreturn .= '<option value="1"';
if (!(strcmp("1", $fvar_YesNo)))
{
$ynreturn .= "SELECTED";
}
$ynreturn .= '>YES</option>';
$ynreturn .= '<option value="0"';
if (!(strcmp("0", $fvar_YesNo)))
{
$ynreturn .= "SELECTED";
}
$ynreturn .= '>NO</option>';
$ynreturn .= '</select>';

return $ynreturn;
}

musher
09-03-2006, 04:31 AM
What does "page source" look like on the processed page?

Wow this is strange.... this is the page source from test 2

<select class="text_update" name="emailer">
<option value=""SELECTED>Select Yes or No</option>
<option value="Y">Yes</option><option value="N">No</option>
</select>
<tr><td class="ok_cls">Test 2: </td><td></td></tr>

mic2100 I'll take a look at your fix, but I'd really like to know why this is happening.

Brandoe85
09-03-2006, 04:46 AM
I'd say, in this line:


echo '<tr><td class="'.$parm_emailer_class.'">Test 2: </td><td>' . YesNo_selection($hold_emailer, $var_field_name) . '</td></tr>' . "\n";

The echo in the function is going to finish before the echo '<tr><td' ... etc.

So, the function stuff is going to be echo'd before the <select>. the fix would indeed be to have the function return the value.

Good luck;



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum