Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Maintaining List Box State

Status
Not open for further replies.

neroe

Technical User
Feb 27, 2003
54
GB
The scenario;
I have a questionaire (containing 13 questions). The methods of answering the questions are a mix of dropdown lists (and then a 'Next'link) and links. Only one question at a time appears on the ASP, so it basically submits to its self each time producing the next question. The answers get stored to the querystring that builds as the questions go by.

The problem;
I would like the list box entries to maintain the answer that the users give should they go back through the questionaire. At the moment, should the user go back for whatever reason a list box question appears in the unanswered state i.e. Please Select . . .

Where I am upto;
I have created an array to store the Session values in i.e. The answer values . . . I just need to grab this value and set it as 'Selected' in the dropdown list when the user revisits that question . . . sounds straight forward but I am stuck . . .

Not sure if I have explained this as intended (!), thanks for any help . . .
 
This is more of an ASP than HTML question. Basically, if user pushes the back button, there is really not knowing what browser will do, because when pressing back browsers usually do not request the page again. So caching answers is basically up to browsers in that case. If you go back via a link, it is simply a matter of putting the variable into the field. You can do it at any time. In pseudo code.

1. check session if the answer for this question exists
2. if it exists, make the option that matches it selected
3. print
 
Thanks for your reply. Your suggestion is exactly what I just started working on.
Thanks again . . . I shall go find the ASP forum next time aswell!
 
Here's another alternative. Add this function to your page:
Code:
function SelectOption(daFld,daVal) {
  var daCtl = document.form1.elements[daFld];
  for ( var x = 0; x < daCtl.options.length; x++ ) {
    if ( daVal == daCtl.options[x].value ) {
      daCtl.options[x].selected = true;
    }
  }
}
Then add this javascript code at the bottom of your page. You can add code to see if the variable is set first if you need to.
Code:
SelectOption("[i]optname[/i]","<%=[i]varname[/i]%>");
I've got similar ones I use for radio buttons and checkboxes.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
tsdragon . . . could you send me a page with this code working correctly?
 
I supposed I could, but it would be more like 4 or 5 files than a single page (I used includes a lot, especially for utility code like that). There really isn't a lot point though, there's little in them that pertains other than the code I posted above.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
If I can find time this coming week, I will post example code (maybe a FAQ) about it, but it won't be until later in the week. My boss dropped a project and my desk late Friday afternoon and said he wants it done Tuesday.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top