Generic Form Parsing

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Generic Form Parsing

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Generic Form Parsing

Post by s.dot »

This is where I let jQuery do the dirty work. :-D A simple call to ${'form'}.serialize() :P
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Re: Generic Form Parsing

Post by Parody »

Thanks. I forgot jquery could help. I already use it. :D
Parody
Forum Contributor
Posts: 252
Joined: Fri May 06, 2005 7:06 pm
Location: Great Britain

Re: Generic Form Parsing

Post 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
Post Reply