How can I retain value of pulldown list in form?

Discussion in 'ASP General' started by Mark R, Apr 2, 2004.

  1. Mark R

    Mark R Guest

    I have one .asp page with a SELECT pulldown list on it and some INPUT
    fields. When SUBMIT is clicked the form data is submitted to that same page
    and validated. If INPUT fields are empty the asp code will insert a visual
    indicator (e.g. *) to convey that the field must be filled in.
    However, if the user has made a selection in the pulldown list and has left
    an INPUT field empty, when the form reappears after validation, the pulldown
    menu looses its selection and returns to its default value.

    Would anyone be able to provide a solution to this?
    Or do you need to see the code first?

    If someone can help I haven't got great asp knowledge so please be as clear
    as possible.

    Thanks a lot.
     
    Mark R, Apr 2, 2004
    #1
    1. Advertising

  2. Mark R

    Roland Hall Guest

    "Mark R" wrote in message news:c4j9pb$4k$...
    : I have one .asp page with a SELECT pulldown list on it and some INPUT
    : fields. When SUBMIT is clicked the form data is submitted to that same
    page
    : and validated. If INPUT fields are empty the asp code will insert a visual
    : indicator (e.g. *) to convey that the field must be filled in.
    : However, if the user has made a selection in the pulldown list and has
    left
    : an INPUT field empty, when the form reappears after validation, the
    pulldown
    : menu looses its selection and returns to its default value.
    :
    : Would anyone be able to provide a solution to this?
    : Or do you need to see the code first?
    :
    : If someone can help I haven't got great asp knowledge so please be as
    clear
    : as possible.

    Test the values when the page is loaded and if not empty, then data has been
    entered and you can set the values, along with the * for the fields that are
    not empty.

    or

    You can validate client-side scripting before you post so when you do post,
    everything will work and you do not waste an expensive trip to the server.

    HTH...

    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Apr 2, 2004
    #2
    1. Advertising

  3. Mark R

    Mark R Guest

    Thanks for your efforts Roland.

    I think I just found after much searching, the answer that I was looking
    for.
    By putting <% if country="United States" then %>SELECTED<%end if%>
    in the option tag, the selection won't be lost!

    I absolutely love it when you get stuck and eventually find the answer.
    Usually though I think I find the answer and then I find another problem
    down the line, so I hope it works.....

    Sorry if my initial question wasn't clear enough.

    Mark

    <%
    ....
    country = Request.Form("country")
    %>
    ....
    <select name="country">
    <option value></option>
    <option value="United States"
    <% if country="United States" then %>SELECTED<%end if%>
    >United States</option>

    <option value="Afghanistan"
    <% if country="Afghanistan" then %>SELECTED<%end if%>
    >Afghanistan</option>

    <option value="Albania"
    <% if country="Albania" then %>SELECTED<%end if%>
    >Albania</option>

    ....



    "Roland Hall" <nobody@nowhere> wrote in message
    news:...
    > "Mark R" wrote in message news:c4j9pb$4k$...
    > : I have one .asp page with a SELECT pulldown list on it and some INPUT
    > : fields. When SUBMIT is clicked the form data is submitted to that same
    > page
    > : and validated. If INPUT fields are empty the asp code will insert a

    visual
    > : indicator (e.g. *) to convey that the field must be filled in.
    > : However, if the user has made a selection in the pulldown list and has
    > left
    > : an INPUT field empty, when the form reappears after validation, the
    > pulldown
    > : menu looses its selection and returns to its default value.
    > :
    > : Would anyone be able to provide a solution to this?
    > : Or do you need to see the code first?
    > :
    > : If someone can help I haven't got great asp knowledge so please be as
    > clear
    > : as possible.
    >
    > Test the values when the page is loaded and if not empty, then data has

    been
    > entered and you can set the values, along with the * for the fields that

    are
    > not empty.
    >
    > or
    >
    > You can validate client-side scripting before you post so when you do

    post,
    > everything will work and you do not waste an expensive trip to the server.
    >
    > HTH...
    >
    > --
    > Roland Hall
    > /* This information is distributed in the hope that it will be useful, but
    > without any warranty; without even the implied warranty of merchantability
    > or fitness for a particular purpose. */
    > Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    > WSH 5.6 Documentation -

    http://msdn.microsoft.com/downloads/list/webdev.asp
    > MSDN Library - http://msdn.microsoft.com/library/default.asp
    >
    >
     
    Mark R, Apr 2, 2004
    #3
  4. Mark R

    Roland Hall Guest

    "Mark R" wrote in message news:c4jg9e$8in$...
    : Thanks for your efforts Roland.

    You're welcome.

    : I think I just found after much searching, the answer that I was looking
    : for.
    : By putting <% if country="United States" then %>SELECTED<%end if%>
    : in the option tag, the selection won't be lost!

    That's what I was referring to with my first option. You're grabbing the
    posted value and setting it.

    : I absolutely love it when you get stuck and eventually find the answer.
    : Usually though I think I find the answer and then I find another problem
    : down the line, so I hope it works.....
    :
    : Sorry if my initial question wasn't clear enough.

    Glad you got it working. (O:=


    --
    Roland Hall
    /* This information is distributed in the hope that it will be useful, but
    without any warranty; without even the implied warranty of merchantability
    or fitness for a particular purpose. */
    Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
    WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
    MSDN Library - http://msdn.microsoft.com/library/default.asp
     
    Roland Hall, Apr 2, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neil Marshall

    Writing a pulldown menu tutorial

    Neil Marshall, Feb 18, 2004, in forum: HTML
    Replies:
    0
    Views:
    384
    Neil Marshall
    Feb 18, 2004
  2. leicklda
    Replies:
    1
    Views:
    394
    Beauregard T. Shagnasty
    May 16, 2006
  3. .Net Sports
    Replies:
    2
    Views:
    830
    Evertjan.
    Oct 27, 2009
  4. cgplays.com
    Replies:
    1
    Views:
    117
    Pachydermitis
    Aug 16, 2003
  5. Claire Osborne
    Replies:
    2
    Views:
    120
    kaeli
    Feb 18, 2004
Loading...

Share This Page