syntax for retaining value in a drop down box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • raaman rai
    New Member
    • Oct 2007
    • 114

    #1

    syntax for retaining value in a drop down box

    Please kindly tell me how to retain a value in the drop down box. I mean if i have a form and i select one option from the drop down box, and when i submit the form, if something is wrong in the submission, the very form is returned with all the values intact. But incase of me i am not able to retain the value in the drop down box. Please see my code:

    [PHP]
    <td class="smallfie ldcell">
    <?php echo $form->error("class") ; ?>
    <select name="class" tabindex="2" id="class"><?ph p echo $form->value("class") ; ?>
    <option>Selec t</option>
    <option value="A">A</option>
    <option value="B">B</option>
    <option value="C">C</option>
    <option value="D">D</option>
    </select>
    </td>
    [/PHP]

    requesting for your urgent reply.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    You could save the form values in the SESSION.

    Comment

    • raaman rai
      New Member
      • Oct 2007
      • 114

      #3
      Yes the values are saved as shown in the code:
      [HTML]
      <?php echo $form->value("class") ; ?>
      [/HTML]

      i can store this in a variable and use it. Now i just want to know how this variable can be used in the drop down box to show the value.

      Comment

      • Gulzor
        New Member
        • Jul 2008
        • 27

        #4
        try something like that :

        <option value="a"<?php if ($sav == "a") echo ' selected="selec ted"; ?>>blabla</option>
        <option value="b"<?php if ($sav == "b") echo ' selected="selec ted"; ?>>blabla</option>
        <option value="c"<?php if ($sav == "c") echo ' selected="selec ted"; ?>>blabla</option>
        <option value="d"<?php if ($sav == "d") echo ' selected="selec ted"; ?>>blabla</option>

        where $sav is the retained value

        Comment

        • raaman rai
          New Member
          • Oct 2007
          • 114

          #5
          Yea i have already implemented a similar solution and it worked. Anyway thanku somuch.
          Originally posted by Gulzor
          try something like that :

          <option value="a"<?php if ($sav == "a") echo ' selected="selec ted"; ?>>blabla</option>
          <option value="b"<?php if ($sav == "b") echo ' selected="selec ted"; ?>>blabla</option>
          <option value="c"<?php if ($sav == "c") echo ' selected="selec ted"; ?>>blabla</option>
          <option value="d"<?php if ($sav == "d") echo ' selected="selec ted"; ?>>blabla</option>

          where $sav is the retained value

          Comment

          Working...