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 6 of 6
  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts

    slected selected

    This code is in the update form but somehow it does not work. Would appreciate any help.

    PHP Code:
              <td nowrap="nowrap" align="right">Month:</td>
              <td>
                  <?
    //selector_s4_dis: dynamically selects a value in a select according to what's already in the DB

    function selector_s4_dis($dis)
    {
        
    $arr = array('January''February''March''April''May''June' 'July''August''September''October''November''December');
        for(
    $i 0$i count($arr); $i++)
      {
          
    $selected = ($arr[$i] == $dis) ? 'selected="selected"' '';
          echo 
    "<option value=\"{$arr[$i]}\" {$selected}>{$arr[$i]}</option>\n";
      }
      
    //return;
    }
     
    ?>     
                      
              <select input type="text" name="month" id="month">
                       <option value="January" selected="selected">January</option>
                        <option value="February" >February</option>
                        <option value="March" >March</option>
                        <option value="April" >April</option>
                        <option value="May">May</option>
                        <option value="June" >June</option>
                        <option value="July" >July</option>
                        <option value="August" >August</option>
                        <option value="September" >September</option>
                        <option value="October" >October</option>
                        <option value="November" >November</option>
                        <option value="December" >December</option>
     </select></td>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    What you have there is a PHP function.
    It has to be called from someplace ... in a script somewhere.

    What you're showing us means nothing.

  • #3
    New Coder
    Join Date
    Jan 2010
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Somehow I tried different methods they just cannot work. Please help, thanks.

    PHP Code:
    <td>          
    <select input type="text" name="month" id="month">
    <? for($i=0;$i<11;$i++) { ?>
    <option value="<?=$i?><? if($i==$selected) echo 'selected="selected"';?>><?=$i?></option>
    <? }//end for ?>
                  
     <option value="January" selected="selected">January</option>
     <option value="February" >February</option>
     <option value="March" >March</option>
     <option value="April" >April</option>
    <option value="May">May</option>
    <option value="June" >June</option>
     <option value="July" >July</option>
    <option value="August" >August</option>
    <option value="September" >September</option>
     <option value="October" >October</option>
    <option value="November" >November</option>
      <option value="December" >December</option>
     </select></td>

  • #4
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    try something like this;

    PHP Code:
    $arr = array('January''February''March''April''May''June''July''August''September''October''November''December');

    $dis "May";

    echo 
    "<select>\n";
    foreach(
    $arr As $Month){
        if(
    $dis == $Month){
            echo 
    "<option value='" $Month "' SELECTED>" $Month "</option>\n";
        }    else {
            echo 
    "<option value='" $Month "'>" $Month "</option>\n";
        }

    }
    echo 
    "</select>"

  • #5
    New Coder
    Join Date
    Jan 2010
    Posts
    36
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks. I am really clueless of where to put those code.

  • #6
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    i've updated your script:

    PHP Code:
              <td nowrap="nowrap" align="right">Month:</td>
              <td>
                  <?
    $arr 
    = array('January''February''March''April''May''June''July''August''September''October''November''December');

    echo 
    "<select>\n";
    foreach(
    $arr As $Month){
        if(
    $dis == $Month){
            echo 
    "<option value='" $Month "' SELECTED>" $Month "</option>\n";
        }    else {
            echo 
    "<option value='" $Month "'>" $Month "</option>\n";
        }

    }
    echo 
    "</select>";  

    ?>
    </td>
    that should work.


  •  

    Posting Permissions

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