views:

348

answers:

1

Basically, I have a form that has some pretty date-sensitive info in it. The risk with the form being cached is that:

1) The user may not notice that the date is wrong and simply think that the server has loaded their saved data (which it should, if the date was correct). They then submit the data and it gets saved to the wrong date. They don't notice until the following week or when they get yelled at for submitting no form for the right week.

2) The user notices but thinks the error is server-side. They reload the form from the browser instead of submitting the date-change form to get the right date, all wackiness ensues...

So, I was thinking that, since all attempts to deal with caching on the server side seem to have minimal effect on the situation, that perhaps there was a more clever way...

Both ideas are based on the assumption that the browser only uses cached data if the input form is empty (no value). So first question, is this true?

If it is, I'm wondering which of these ideas would be more effective:

1) The server script simply sets all inputs to 0. I then have a js script that on page load sets all inputs with 0 to "". (0 will never be a possible entry, in case that set off any bells).

2) Leave the server script alone, and simply have the above mentioned javascript go through each input and change the value() of the input to the attr("value") of the input. So if it's non-existant, it sets it to blank.

Any flaws in my understanding of browser caching or whatnot? Will either method work better?

Sample of the second idea:

$("input :text").val(function() {
        realval = (!($this).attr("value")) ? 0 : $(this).attr("value");
        return realval;
        });
A: 

Use different ids and names for your input fields by extending it with a session id.

e.g. the session id 12345

<input type="text" id="12345_firstname" name="12345_firstname" />

The browser won't touch those fields.

Another approach might be to set all input fields to disabled and setting them back to enabled with jQuery after the document did load.

<INPUT NAME="firstname" DISABLED>
$("input").removeAttr("disabled");
Ghommey