Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Select the default value based on previous selection in select box

 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Type of cars<select name="typeofcars" id="typeofcars">
<option value="Volvo">Volvo</option>
<option value="Indica">Indica</option>
<option value="Sumo">Sumo</option></select>

I give an option to the user to select any type of car.Suppose the user selects,"Volvo" and hit the submit button.I store the value selected in say some "cookie".Next time the User comes into the same page,I want to display the select box, with "volvo"(the value he selected earlier) already selected.Also, the important point is that, i still have to have other values,just in case if the user wants to select some other car type.
how do i accomplish this




 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basic HTML: set the selected attribute on the appropriate option element.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you mean to say i need to write something like this


right?

If you meant this,then iam afraid that you didnot read my question properly, or may be i was not clear enough.If i do this, I always show "Volvo" as default value.
Let me repeat what my question was to be more clear

I give an option to the user on my "search page "to select any type of car.Suppose the user selects,"Volvo" and hit the submit button.I store the value selected in say some "cookie".Next time the User comes to the "search page" (into the same page),I want to display the select box, with "volvo"(the value he selected earlier) already selected.Also, the important point is that, i still have to have other values,just in case if the user wants to select some other car type.
how do i accomplish this

So when the user comes in for the second time, I show "volvo" as default value. Now, user opts to select, say another car type , say "Indica" and hits submit button.Now, the user comes to the "search page" again, this time he should see default value as "Indica" instead of "volvo". That is how i want it to be. Hope iam more clear now.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I understood perfectly.

As I said, put the selected attribute on the appropriate option element. In other words, the one that was previously selected. You have this information available because it was part of the form submission.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess, then i have to create this "select box" every time on a fly, or say dynamically and put the "selected" attribute appropriately. Right?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65535
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct.
 
Maan Suraj
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!