Javascript problem on refresh
I am having a problem that I cant figure out. What I am currently doing, is when you select a value in a dropdown certain text displays based on your selection, but when I refresh the page, the text gets wipped out. I need the text to remain there when the page gets refreshed. I tried calling the function that shows/hides text onload but that doesnt seem to be working either.
Please help!!
This is my javascript code that changes the text that gets displayed.
Code:
<script language="JavaScript">
<!--
function ShowHide(v, x) {
if (v.value == "2D")
x.style.display = "block";
else if (v.value == "1T")
x.style.display = "block";
else if (v.value == "SS")
x.style.display = "block";
else
x.style.display = "none";
}
function doLoad() {
ShowHide(document.form[0].var5.value, showOptionsThurs);
}
// end -->
</script>
<BODY ONLOAD="javascript:doLoad()">
This is the code for the dropdown that I am using.
Code:
<SELECT id="var5" NAME="dropown_var5" class="text" onClick="ShowHide(this, showOptionsThurs);">
<OPTION VALUE=""> ---------- Please Select One ----------
<OPTION VALUE="EO"> EO
<OPTION VALUE="2D"> 2D
<OPTION VALUE="1T"> 1T
<OPTION VALUE="1F"> 1F
<OPTION VALUE="SS"> SS
</SELECT>
This is the code that is used to display the text.
Code:
<tr id="showOptionsThurs" STYLE="DISPLAY:NONE;" >
<TD colspan="1">
Display Text
</TD>
</tr>
Re: Javascript problem on refresh
refreshing the page returns the stucture to the origional, as is written in the code. you will need to save the data before unloading, and reload it after. it would be easiest to simply save the selectedIndex of your combo, and change it back when the page loads.
uses document.cookie to store the index.
Re: Javascript problem on refresh
If you look at my code, when the page loads, i do look at the variable in the following line
document.form[0].var5.value
It knows what was selected but then for some reason when I call the showHide function it doesnt reset everything.
Re: Javascript problem on refresh
i don't see any static (persistant) variables here. sometimes form values survive reload, sometimes they don't. is there a difference between hitting F5, and CRTL+F5?
"when I call the showHide function it doesn't reset everything."
if your form remembers stuff, perhaps the script is mis-matching your conditions.
try this:
Code:
x.style.display = ("2D1TSS".indexOf(v.value.toString()) > -1) ? "block" : "hidden";
Re: Javascript problem on refresh
oh wait a second, your got a bug in your code i just noticed.
you pass document.form[0].var5.value to ShowHide(v, x) as v.
then, you ask if (v.value == "2D").
so what you are actually comparing is:
document.form[0].var5.value.value !
remove one of the .values, and it will be better.
i would remove it from the comparisons, each time you use a dot in javascript it takes a while.
[resolved] Javascript problem on refresh
That was it, thanks for the help rnd me!!!!