drop-down position

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • @net

    drop-down position

    Hi,
    I have page1.php with form to fill by customer. Inside form is field
    with dynamic drop-down menu (choices from database). On page2.php I
    have validation of values posted from page1.php. In case or error or
    forbiden values, customer is redirected to page1.php again (with proper
    error notification) to correct them. All the values should be preserved
    on redirection to page1.php by session variables, so the customer dont
    have to fill all the fields again, but only to make correction. It's
    easy with <input type="text"...
    Now the question:
    How to preserve the position choosed from first submition in drop-down
    menu since it is dynamicly populated?

    THX, everyone.

  • usenet+2004@john.dunlop.name

    #2
    Re: drop-down position

    @net:
    All the values should be preserved on redirection to page1.php by
    session variables, so the customer dont have to fill all the fields
    again, but only to make correction. It's easy with <input
    type="text"...
    Now the question:
    How to preserve the position choosed from first submition in
    drop-down menu since it is dynamicly populated?
    Pick the value out of the session and compare it with the values in
    your SELECT. It doesn't matter whether or not those values are pulled
    from a database. Whichever one matches the value from the session, add
    to its OPTION a selected="selec ted" attribute spec.

    --
    Jock

    Comment

    • Kim Hunter

      #3
      Re: drop-down position

      @net wrote:
      Hi,
      I have page1.php with form to fill by customer. Inside form is field
      with dynamic drop-down menu (choices from database). On page2.php I
      have validation of values posted from page1.php. In case or error or
      forbiden values, customer is redirected to page1.php again (with proper
      error notification) to correct them. All the values should be preserved
      on redirection to page1.php by session variables, so the customer dont
      have to fill all the fields again, but only to make correction. It's
      easy with <input type="text"...
      Now the question:
      How to preserve the position choosed from first submition in drop-down
      menu since it is dynamicly populated?
      >
      THX, everyone.
      >
      heres a function i wrote the other other day, you could change it to
      loop through the db result, cause this one was for a static array

      function arrayToOptions( $array,$selecte d = null)
      {
      $result = "";
      foreach( $array as $value =$name )
      {
      $result .=
      sprintf('<optio n value="%s"%s>%s </option>',
      $value,($value == $selected)
      ? ' selected="selec ted"': "",$name);
      }
      return $result;
      }

      Comment

      Working...