I am facing a weird problem, may be some of you have already faced it. Here is the issue,

I have a hidden input field in my html ( using perl /mason ),

<input type='hidden' id='noB'  name='noB' value='<% $noB%>'/> ; 

value ($noB) is filled at server side.

In my javascript, I am using

var noB = jQuery('#noB').val(); 

to get value and process it.
Most important thing is everytime I will access this value inside a javascript function in a new variable assume noB = 3, do some processing and update the hidden variable noB with new value as 1, so its not a global variable which I am using to do that.

Now, if I change noB lets say 1 in my javascript and after that page is refreshed using F5, when the page loads again and I try to get value.

var noB = jQuery('#noB').val();

I get noB = 1 only, when It should be 3.

Please help.

3

There are 3 answers

1
Anthony Grist On

Firefox (and possibly other browsers) will reload form elements with the values they had when you refreshed the page, even if that's not the value specified in the HTML. Simple solution: reload the page by navigating back to it, rather than refreshing.

0
Raj On

If this is a browser issue, try forcing the browsers not to cache your page content.

This can be done by putting the following <meta> tag inside your HTML header:

    <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
0
Prashant Agarwal On

Although its very old one but I ran into a similar problem and found this solution:

  1. Instead of using hidden input field, use a label.innerHTML to store your value
  2. You can access/alter label's innerHTML value using javascript.
  3. Label's value will get refreshed each time the page is refreshed.

Hope it helps.