Daniel Jo
Daniel Jo

Reputation: 350

Access to HTML forms via jQuery

How do I get an inputs content in jQuery. Like this option in JavaScript:

document.forms["Register"]["userName].value

Thanks

Upvotes: 1

Views: 29

Answers (2)

MSH
MSH

Reputation: 1287

Use like :

$('form[name="form1"] [name="name"]').val();

See example :

http://jsfiddle.net/maddyjolly2112/gfn46ckx/

Upvotes: 1

Jai
Jai

Reputation: 74738

You can use this:

$('form[name="Register"] [name="userName"]').val();

using .filter():

$('form[name="Register"] input').filter(function(){
    return $(this).attr('name') === 'userName'
}).val();

Upvotes: 1

Related Questions