Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2006
    Posts
    76

    confused alittle bit

    Hi, I am just confused about this year dropdown-list.
    all what I need is how do I make a specified year selected Ex."1970" automaticaly?.
    Code:
    <select name="year" id="year">
              <?
    		   for($y =1940; $y<=2000; $y++)
    	  		{
    	  		
    			echo "<option value =$y >$y</option>";
    	  		   
    			}
    			
             ?>
    </select>
    I appreciat your help

  2. #2
    Join Date
    Mar 2006
    Location
    South Australia
    Posts
    4,521
    Like this:

    Code:
    <select name="year" id="year">
        <?
            $selectedYear = 1970;
            
            for($y =1940; $y<=2000; $y++)
            {
                if ($y == $selectedYear) {
                    echo "<option value =$y SELECTED>$y</option>";
                }
                else {
                    echo "<option value =$y>$y</option>";
                }
               
            }
    
        ?>
    </select>

  3. #3
    Join Date
    Jul 2006
    Posts
    76
    Thank you very much Mr Charisma, I really appreciat your help

  4. #4
    Join Date
    Mar 2004
    Posts
    0
    this code does not meet the standard well. Here, I changed it up a bit:

    Code:
    <select name="year" id="year">
        <?
            $selectedYear = 1970;
            
            for($y =1940; $y<=2000; $y++)
            {
                if ($y == $selectedYear) {
                    echo "<option value = \"$y\" selected = \"selected\">$y</option>";
                }
                else {
                    echo "<option value = \"$y\">$y</option>";
                }
               
            }
    
        ?>
    </select>
    note the ". Non-standard HTML code should be avoided....



Posting Permissions

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