views:

279

answers:

2

Hi,

I have build a quite complex widget which contains "some kind of form". It has a form tag, but I'm loading a lot of stuff in there via Ajax etc. Cannot explain it in detail, and the code is too long to paste in here.

Now, in a "live('click', function()" I use for one of the form fields, I'm writing a couple of values into hidden fields of another form. That works fine, as I can see them in the generated code. But if I leave the page and then hit the back button, the values are gone.

If I write some values into those fields outside the live click function though, they are still there when I leave the page and come back using the back button.

But I need to write the values into the hidden fields out of the live click function (I'm inserting values from fields of my form into them).

I don't know what causes this and wasn't able to find a workaround yet (even though I tried a lot).

Any ideas?

Thanks!

A: 

Have a look at the jquery history plugin (http://plugins.jquery.com/project/history)

Ryan
A: 

Usually what happens is that browser remembers what you have entered into a form (even if you don't submit it) so that when you hit back button, it populates all the visible fields for you.

It seems it's not the case with hidden fields. There's a workaround though.

Every time one of your hidden fields is changed, you can add #part to your url (eg. www.mysite.com/users#userId,groupId,...).

When the page is loaded again (via back button for example), it will contain the #part. Parse it as a string to determine how to populate hidden fields and populate them.

Review the history plugin for jQuery to see how to read the #part.
http://plugins.jquery.com/files/jquery.history.js_0.txt

michal kralik
Hey guys, thanks a lot for the answers. I didn't consider using the history plugin because the examples only dealt with isses you could be having within one Ajax page. But I will have a look at the hash part. BTW: I don't think the hidden fields are the problem here. As mentioned, the browser seemed to remember the values when I wrote them into the fields from outside the live click function. But due to scoping I can't access the variables of this function from outside of it.