At the risk of slightly drifting the subject of this thread, I took a look at the demos for the Field plugin:

http://www.pengoworks.com/workshop/jquery/field/field.plugin.htm#examples

Does anyone know if I can use it to select all of the form fields inside a specific div? IE:

<form id="myForm">
    <div id="personName">
       <input type="text" id="firstName" name="firstName" />
        <input type="text" id="lastName" name="lastName" />
    </div>
    <input type="text" id="jobTitle" name="jobTitle" />
</form>

Then do this to just get firstName and lastName?

var vals = $('#personName').formHash();

IIRC, recently I tried doing that with the native jquery .serialize() and the jquery form plugin and neither would do that: it seemed like they *had *to be passed a selector that found a <form>. IE: $('#myForm').serialize(). Maybe I'm wrong about that? My experiments lead me to believe that.

I'm often working in asp.net and have one form tag per page, but different sets of input fields in the page and would like to be able to easily serialize by set for preparation for ajax calls.

Thanks,
Jack

Dan G. Switzer, II wrote:
Martin,

Check out the Field plug-in:

http://jquery.com/plugins/project/field

This provides the type of functionality you're looking for (of providing
form values back for any type of field.)

-Dan

  
-----Original Message-----
From: jquery-en@googlegroups.com [mailto:jquery-en@googlegroups.com] On
Behalf Of mar10
Sent: Thursday, June 12, 2008 3:17 AM
To: jQuery (English)
Subject: [jQuery] Best practice to get form field values


Hi,

what would you consider the 'best practice' to access form input
values?

Having an input field
   <input value="New topic" class="inputEdit" name="title"
type="text">
I could use
	$('[EMAIL PROTECTED]').val()
or
	$('[EMAIL PROTECTED]"title"]').val()
or
	$('[name=title]').val()
or
	$('[name="title"]').val()

(
I also once observed, that the right side of the '=' was evaluated, so
it was possible to write
   var x = 'title';
   $('[name=x]')
but i could not reproduce it today, so maybe I'm wrong.
)

Of course assigning an additional id
   <input value="New topic" class="inputEdit" name="title"
type="text" id="title">
would allow for
   $('#title')
but that appears to be somewhat redundant to me.

In short I am looking for the most simple built-in syntax to access
form values, like prototype's $F().
This means that querying option lists should return a list of selected
values (or texts), and text areas should work also.


Thanks
Martin
    


  

Reply via email to