Results 1 to 7 of 7

Thread: At below code if I want to use rather selected the selected="selected"

  1. #1
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default At below code if I want to use rather selected the selected="selected"

    At below code if I want to use rather selected the selected="selected"
    Code:
    <?php 
                /* $curdate = getdate(); 
                 $curday = $curdate['mday']; 
                 $curmonth = $curdate['mon']; 
                  $curyear = $curdate['year']; */ 
                 for ($i = 2008; $i <= 2010; $i++) 
                   { 
                      if ($i == $curyear) 
                         echo '<option value="', $i, '" selected>', $i, '</option>'; 
                      else 
                         echo '<option value="', $i, '">', $i, '</option>'; 
                   } 
              ?>

    this is correct below ?

    Code:
    echo '<option value="', $i, '" selected=', '"selected', '">', $i, '</option>';

  2. #2
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    Code:
    echo '<option value = " '.$i.' " selected = "selected">'.$i.'</option>';
    Try this one. I think it will work

  3. #3
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    This should work:
    PHP Code:
    <?php 
                
    /* $curdate = getdate(); 
                 $curday = $curdate['mday']; 
                 $curmonth = $curdate['mon']; 
                  $curyear = $curdate['year']; */ 
                 
    for ($i 2008$i <= 2010$i++) 
                   {
                      echo (
    $i == $curyear) ? '<option value="' $i '" selected="selected">' $i '</option>':'<option value="' $i '">' $i '</option>';
                   } 
              
    ?>

  4. #4
    Join Date
    Jul 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    you don't have to use selected="selected", just write <option value="'.$i.'" SELECTED> and it works!
    This is how I like to do it:
    PHP Code:
    <?php 
                
    /* $curdate = getdate(); 
                 $curday = $curdate['mday']; 
                 $curmonth = $curdate['mon']; 
                  $curyear = $curdate['year']; */ 
                 
    for ($i 2008$i <= 2010$i++) 
                   { 
                      echo 
    '<option value="'.$i.'" '; if($i == $curyear){echo 'SELECTED';} echo '>'$i'</option>'
                   } 
              
    ?>

  5. #5
    Join Date
    Jul 2007
    Location
    Azerbaijan, Baku
    Posts
    144
    Thanks
    11
    Thanked 27 Times in 25 Posts

    Default

    Sm1le, look at thread name...

  6. #6
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    I am using XHTML TRANS. 1.0 and not validate by that, i need to be valid ...

  7. #7
    Join Date
    Jul 2008
    Posts
    199
    Thanks
    6
    Thanked 58 Times in 57 Posts

    Default

    Using my example should make it proper.

Bookmarks

Posting Permissions

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