My favorite way to get form input values and validate them is by using the
each() method.

Here's an example:

$(function()
{
   $('#myForm input[type=text]').each(function()
   {
      switch (this.name)
      {
         case 'first_name':
         // validate the first name input field here
         break;

         case 'email':
         // Something with email here
         break;
      }
   });
}

If this isn't sufficient information I can make a more advanced example for
you.

On Thu, Jun 12, 2008 at 9:16 AM, mar10 <[EMAIL PROTECTED]> wrote:

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

-- 
Isaak Malik
Web Developer

Reply via email to