Page 1 of 1

Generic Form Parsing

Posted: Mon Apr 14, 2008 4:31 pm
by Parody
I am looking for short snippet of code to output the names and values of all the inputs of a form for an ajax app.

This is the setup:

Form with button set so that onclick links to an ajax function which picks up the string of variables in GET format for the form to send in the request.

The only problem is that this list of variables is variable and so can't be hard coded into the script. I have found some attempts at this, but none are this simple and want to help validate the inputs.

Layout:

Code: Select all

<form>
<inputs and stuff>
<input type=button onclick=process(this.form)>
</form>
 
Then the javascript:

Code: Select all

function process(form){
 
getform=getform(form);
 
DO AJAX STUFF using the string formed with the getform function from the form
}
 
I know it's a simple FOR statement, but I'm new to javascript and this would be a great help.

Thanks

Re: Generic Form Parsing

Posted: Mon Apr 14, 2008 5:42 pm
by s.dot
This is where I let jQuery do the dirty work. :-D A simple call to ${'form'}.serialize() :P

Re: Generic Form Parsing

Posted: Tue Apr 15, 2008 2:08 am
by Parody
Thanks. I forgot jquery could help. I already use it. :D

Re: Generic Form Parsing

Posted: Tue Apr 15, 2008 5:56 am
by Parody
If I needed the string of variables in get format in a non-jquery function variable how could I do it?

Code: Select all

(script)
function ajax(formobject)(
var frmstr=?serializestuff?
DO REST OF FUNCTION
)
(/script)
 
Excuse the terrible use of brackets, im on a phone :D

Thanks