Results 1 to 6 of 6

Thread: Javascript problem on refresh

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    492

    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>
    Last edited by mrstuff68; Jun 9th, 2007 at 01:30 PM.

  2. #2
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    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.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    492

    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.

  4. #4
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    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";
    Last edited by rnd me; Jun 11th, 2007 at 07:54 AM. Reason: tiny bug

  5. #5
    Hyperactive Member
    Join Date
    Jun 2006
    Posts
    372

    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.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    492

    Resolved [resolved] Javascript problem on refresh

    That was it, thanks for the help rnd me!!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width