How can I get the values of all visible fields in a form (with several fields) and set them in a array or something else? After I would like to get these values from the array and set them to the visible fields in the same form (such as a clear and u开发者_如何学JAVAndo function of a form)?
My form has several select-fields, text-fields, textarea-fields and hidden-fields.
Thanks for your help!
By looking up the answer in jquery api guide :) hehe
http://api.jquery.com/serializeArray/
Have answered this question in the below link Submitting form data through a jQuery command . This will be useful. By visible fields do you mean the enabled fields? Look up the jquery api for the serialize method
I could realize it with the jQuery data() method. After storing the form with this method you can extract the values.
The easiest was to do this is to mark all elements in your form with a css class (the class doesn't need to exist in your style sheet). Ie put the class formfield on all of your form inputs. Then you can simply use the jquery class selector to select all of the inputs at once and do what you want to them e.g.
$('.formfield').hide();
The above command will hide all of your form elements but you can use the $('.formfield') selector to do whatever you want to all of the form fields.
精彩评论