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 2 of 2
  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    91
    Thanks
    2
    Thanked 0 Times in 0 Posts

    SELECTED in drop down

    Hi guys, i have a drop down code below



    <select class="input" name="mod[cpu]">
    <option value=""> </option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>
    the output are like this
    $html .= ($content[cpu] ? '<div class="' . $this->switch_bg() . '"><strong>CPU:</strong> ' . @htmlspecialchars($content[cpu]) . '</div>' : '');



    i want after the drop down choosed by user, it will add SELECTED next time they opening the drop down again

    i am still dont know how to put the SELECTED there, please help what is the code to add SELECTED, i only have variable mod[cpu] and $content[cpu]


    i already tried in bold below, but still not working

    <select class="input" name="mod[cpu]" selected="$content[cpu]">
    <option value=""> </option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>




    please share your knowledge
    Whats up

  • #2
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    361
    Thanks
    9
    Thanked 53 Times in 52 Posts
    You might get more responses by posting this to PHP subforum..?

    And how is $content[cpu] related to mod[cpu]? Well just guessing... you probably want something like the following:
    PHP Code:
    <select class="input" name="mod[cpu]">
    <option value=""> </option>
    <?php 
      
    for ($i=1;$i<4;$i++){
        if (
    $i==$content[cpu]){
          echo 
    '<option value="'.$i.'" selected="selected">'.$i.'</option>';
        }
        else{
          echo 
    '<option value="'.$i.'">'.$i.'</option>';
        }
      }
    ?>
    </select>


  •  

    Posting Permissions

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