Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder musher's Avatar
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code (function call) not working in 2nd example

    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

    PHP Code:
    // 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:
    PHP Code:
    // 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>';

    Thanks
    Jim M

    "Lord, help me to become the person my dog thinks I am" - Dawn Ewing
    "If you must know. Yes, I do enjoy running after the dog sled when I fall off" - Me

    www.huskyzone.com -- Woodland Siberians

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    What does "page source" look like on the processed page?

  • #3
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    maybe it as sumthing to do with the way your function operates, instead of returning a value and using the echo on that.

    PHP Code:
    // 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...

    PHP Code:
    // 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;


  • #4
    Regular Coder musher's Avatar
    Join Date
    Jan 2005
    Location
    Minnesota
    Posts
    203
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator
    What does "page source" look like on the processed page?
    Wow this is strange.... this is the page source from test 2
    Code:
    <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.
    Thanks
    Jim M

    "Lord, help me to become the person my dog thinks I am" - Dawn Ewing
    "If you must know. Yes, I do enjoy running after the dog sled when I fall off" - Me

    www.huskyzone.com -- Woodland Siberians

  • #5
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I'd say, in this line:
    PHP Code:
    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;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •