0

I am looking for a way with my form I am currently showing and hiding fields based on the values selected in the dropdowns, What I want to know is.

when i select yes and the field below displays I click submit on the form, if I return to the form the value is still present but the field is hidden again...

How can I prevent that from happening by default?

I want my browser to remember the jQuery change funtions state I left it at after I submit the form.

thechrishaddad
  • 5,726
  • 7
  • 24
  • 29
  • 1
    For these you have to save your change status and send it as additional data to form validation on server side. When you will return to form again you should deserialize/initialize form with given data from server. Problem is that this is not working on back button of web browser. If you wanna be able to save state of your form you must use cookies or localestorage for save states for given form and initialize it again with given values. – pesoklp13 Jul 15 '15 at 12:48
  • Spontaniously i can think of either sending the information which fields were visible as part of the request or using cookies in javascript (e.g. via JQuery : http://stackoverflow.com/questions/1458724/how-to-set-unset-cookie-with-jquery) – Benjamin Jul 15 '15 at 12:49
  • hmm it seems to get tedious like that – thechrishaddad Jul 15 '15 at 12:49

1 Answers1

1

What you want to do is 'refresh fields visibility' in some cases. I suggest you to create such function refreshFieldsVisibility. Such function reads values from the dropdown and shows/hide the proper field. Then call your function:

  1. When elements state is changed, with on('change') events.
  2. When document is ready (this is your case as I understand), with $(document).ready
  3. Any other situation if necessary
njzt
  • 38
  • 4
  • that sounds like an option I might give that a go tomorrow and let you know – thechrishaddad Jul 15 '15 at 12:54
  • So what I did is actually just wrap my .change() conditions in a function and then called the function on change and on load. so it handles browser refreshes and dynamic changes :) – thechrishaddad Jul 16 '15 at 05:05