You can also use the .serialize() method to collect your values:

. . .
data : $("#myform").serialize(),
. . .

That works best on text inputs though.  If you have select boxes - and 
especially if they are multi-select, then you may have better luck with 
the .serializeArray() method.

http://docs.jquery.com/Ajax/serialize
http://docs.jquery.com/Ajax/serializeArray

I find I get the best control by creating my own string for the data 
property though.  On my forms, I often only want a couple of the form 
elements to be submitted.  (i.e. submit an employee ID, not the employee 
name - depending on the purpose of my form of course... )

Hope that helps.

Shawn

jjshell wrote:
> First of all, thanks for your time and answers. I really appreciate
> it. Having made a few tests, the $.ajax approach seems the one that
> fits the most my application.
> 
> Just a few questions:
> 
> 1.
> Can you avoid to explicitely name each field of your form?
> data: "test=" + $("input[name=test]").val(),
> What if a form is dynamically created server-side? Do you also have to
> dynamically create a line for jQuery?
> 
> 2.
> How dows this approach reacts to array fields?
> 
> <input type="text" name="pagetitle[1]" value="test" />
> <input type="text" name="pagetitle[2]" value="some title" />
> <input type="text" name="pagetitle[3]" value="some other title" />
> 
> Thank you again for your time :)

Reply via email to