• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

selecting an option in a select box from session variable

 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a select box with values 200,300,400,500 ... 1000 in a select box in a form.,(lets call this as size)
In my program when the user logs in he has a size selected. I am storing this size in a session variable.
This page which is displayed after 4 pages gets the session value. Now I WANT TO MAKE THE VALUE IN THE SIZE VARIABLE TO BE THE SELECTED OPTION IN THE SELECT BOX.
Eg: If my user is selecting 500, then when my form in the 4 page loads the option that has to be selected in te checkbox has to be 500.
How can I do it ?
Thanks..
Maya
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maya
Set up a variable for each checkbox:
cb1 = ""
cb2 = "" , etc
Then later in the code check the session variable and reset the variable that applies:

Then when yo write the checkboxes to the page just add the variables to them:
<input type=checkbox name=cb1 value='100' <%=cb1%>>
<input type=checkbox name=cb2 value='100' <%=cb2%>>
that should do it for you.
The code is vbscript

Dave
 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave,
Thanks for the response.
But mine is a SELECT BOX not a CHECK BOX.
I am going to try in the format that you suggested.
Any valuable suggestions for the SELECT BOX.
Thanks,
Maya
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The principle is the same jus use the variable to set the selected index of the select box.

that should work

Dave
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I already have had this kind of problem. Here the code I used
for(var i = 0;i < formName.selectBoxName.length;i++){
if ( formName.selectBoxName.options[i].value == sessionVariableValue){
formName.selectBoxName.selectedIndex = i;
break;
}
}
I don't know how you get the session variable but this code should help a little bit.
But if you don't set any value to the options of the selectBox, replace in the code formName.selectBoxName.options[i].value by formName.selectBoxName.options[i].text.
For information, options of a selectbox have 2 principal properties: text, which is displayed in the page, and value, which is sent to the url set in the property "action" of the form.
 
Shreya Menon
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Xavier.
I shall try it and let you know.
Maya
 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Passing data from the server side to the client side is deceptively easy. For example:
var serverVar = "<%=sessionVariableValue%>";
for(var i = 0;i < formName.selectBoxName.length;i++){
if ( formName.selectBoxName.options[i].value == serverVar){
formName.selectBoxName.selectedIndex = i;
break;
}
}
This will allow you to also dynamically write the select box from the server side with the desired session level variable selected.
Hope that helps.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Will this work for selecting multiple selections from the select box? If so, how?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic