Click to See Complete Forum and Search --> : keeping state when hitting the "back" button


sleeper
08-01-2003, 12:19 PM
I have two radio buttons: File and Paste, they're both within <form> tags.

The default is File and I displays a file chooser right under it. I made a Javascript function which is called by onClick when you click Paste, and it will show a textbox.

My problem is when after you hit "Submit" (a button on the bottom of the that will display a different HTML), and then press the "Back" button. Back on the original page, it will have "Paste" radio still clicked, BUT it will show the file chooser.

I actually have multiple sets of these radio buttons on the page and I want all of them to be set correctly if the user goes back. I tried to use onLoad, but onLoad needs to be in a <body> tag, meaning that I won't have form yet. Furthermore, the javascript function that displays the textbox, for example, takes in "this" as well as "form" so it knows what was clicked.

Thanks a lot!

sleeper
08-01-2003, 12:39 PM
Here's some of the code to show what I mean:

HTML:

<input type="radio" name="intype" value="file" checked onClick="javascript:change_intype(form, this);" />File
<input type="radio" name="intype" value="paste" onClick="javascript:change_intype(form, this);" />Paste
<br /><br />
<input type="file" name="infile" size="50" />
<textarea class="hide" name="inpaste" cols="100" rows="10" wrap="virtual"></textarea>


Javascript:

function change_intype( form, t ){

for(var i = 0; i < form.length; i++){
if(form.elements[i].type == "file" && form.elements[i].name == "infile"){
if(t.value == "file"){
form.elements[i].style.display = "block";
form.elements[i + 1].style.display = "none";
}else if(t.value == "paste"){
form.elements[i].style.display = "none";
form.elements[i + 1].style.display = "block";
}
}
}
return true;
}