Forum Moderators: open
The user fills out the form and hits submit. A server side script validates the form, and if not valid (duplicate ID for example), the redirect is set to the same page, and all the form fields, including the select and checkboxes are set to what the user entered using value = Response.Form("field")
Works very nicely - especially on one page where there are about 25 or more user inputs. It was very annoying to the user to go back to a blank page after everything was entered.
It seems that when a page is unloaded (submit or whatever) the history not only remembers the page it remembers all the values of all form elements at the point of exit (including those set by JavaScript - not just user modifications). Also you have no server scripting power as clicking back doesn't contact the server for the last page loaded - it takes it all from memory.
You should be able to use an onload event to select te correct selectedIndex. eg:
<body onload="document.myForm.mySelectBox.selectedIndex=1">
When the page is loaded normally the selectedIndex will be selected as you wished. When the user clicks back the onload event will still fire selecting your chosen select option - overriding that in the browsers history.
I have to admit I haven't yet tried this in NN4 or Opera - let us know how you get on.
>This stuff is tricky
Yes, but the above works just fine. For others that might use this, I'll add that the selectedIndex= apparently counts the number of options starting with zero, so the above example actually selects the 2nd option in the selectbox.
>NN4
I tried it on N4.08, N6.2, & IE 6.0.2600 (PC). Works. Thanks!