Page 1 of 1

JavaScript

Posted: Fri Apr 04, 2003 7:02 am
by Johnm
Hi All,
I have a form that has multiple select and input boxes. On changing a value in the first select box I use JavaScript to dynamically change the options in other select and input boxes, then the user selects from the options created dynamically in the second select box and that dynamically changes the options in a third select box. Then the user may select an option in the third select box which will change values on the remainder of the form. This is all fine and well until the user submits the form and moves to the next page. When the user is on the next page all of the $_Post values are correct but if the user clicks the browsers back button the dynamically created values in the third select box on the first page are either wrong or missing.
This is a major problem as the concept is to allow the user to configure equipment that we make. The first select box is for the units type which based on the units type, things are changed in the second select box showing options that are available for that type of unit. Based on the changes in the second select box the available model numbers are displayed in the third select box allowing the user to select from available model numbers. Based on the user selected model number in the third select box things like size, height and width are set on the rest of the form. If the user selects the model number they want, moves to the next page, then uses the browsers back button to go back to the first page and the model number is wrong or missing I risk (and we all know how users can be) submitting bad data which just is not acceptable.
Can anyone help?

John M

Posted: Fri Apr 04, 2003 9:04 am
by daven
Cookies or sessions seem to be the only way to handle this.
After submittal, set the cookie/session val, and then check for it on the form page.

ie--
if(isset(#Cookie/SessionVar)){$select_Val1=#cookie/session_val;}
else{$select_Val1='';}
echo <select name="select1">
if($value=$select_Val1){echo <option value=$value selected>$option</option>;}
else{ echo <option value=$value>$option</option>;}
echo </select>

Yes, I know that I have not used proper syntax, but I am tired and working on a server problem at the moment

Posted: Fri Apr 04, 2003 12:06 pm
by Johnm
How would that work? The form does not get parsed again when the user uses the back button.


John

Posted: Fri Apr 04, 2003 12:50 pm
by daven
Oh. Point. I mis-interpreted your original question.

I cannot think of a way to force the browsers to save the proper selections. The only thing I can think of is to either create a 'back' button on your page (ie--a form) or to use javascript to auto-refresh the page ever time it is accessed (force reloading of form)

Posted: Sat Apr 05, 2003 4:21 am
by Skyzyx
From what I can tell, you need to use JavaScript cookies to save the values entered on the page with the form.

Then, you need to write a script on that same form page that looks for those cookies. If the user is going to that page for the first time, defaults are used.

However, if they have already submitted the form, and have clicked back on the browser, the script will read those cookies that were set and will automatically reload the appropriate information (automatically selecting options in pull-down menus and such)...

If you need more specific help, post a URL, and I'll do my best to help you throw something together. =)

Posted: Sat Apr 05, 2003 8:10 am
by Johnm
That is exactly what I did, but thanks. A note for anyone else that is reading this: Make sure that you destroy the cookies when you are done with them!
John M