www.webdeveloper.com
Results 1 to 5 of 5

Thread: selected option problem

  1. #1
    Join Date
    Sep 2006
    Posts
    8

    selected option problem

    Hi!
    I have a drop down menu created with a select tag and i use two option tags for putting the following values in it:
    1. "Select All"
    2. The rest of the values which come from a query from a database.

    Each time I enter the page I want to have selected as a first option, the previous selection and if there is no previous selection (if I enter the page for the first time or never used this menu before), I want pre-selected the "All" option.
    The code up to now -without using the "selected" attribute- looks like this:

    <select>
    <option value="0">All</option>
    <c:forEach var="row".......>
    <option value="row.value">row.valueName</option>
    </c:forEach>
    </select>

    I would appreciate any help.

  2. #2
    Join Date
    Dec 2005
    Location
    India
    Posts
    490
    r u storing the previous selection in Database?
    If not, u can store the selected value in a Cookie(before the submitting the form).
    And while the page loads, the Cookie value needs to be checked and if some value is present, compare it with each of the values retrieved from the database and make the appropriate option "selected".

  3. #3
    Join Date
    Sep 2006
    Posts
    8
    i do have access to the name and value of the option previously selected.
    But since this previous option is one of the many possible which come from the <c:forEach> loop, i can't tell where to put the "selected" attribute.

  4. #4
    Join Date
    Dec 2005
    Location
    India
    Posts
    490
    If you're not storing the previous value in database, then you have make the default selection using Cookies.

    chk this site.. it'll be a gud start to work on Cookies
    http://www.quirksmode.org/js/cookies.html
    or search for examples on Cookies. u'll find lots of them online.

  5. #5
    Join Date
    Sep 2006
    Posts
    8
    never mind. i got it

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles