Altiano Gerung Altiano Gerung - 1 year ago 61
jQuery Question

Get a submitted form value using jQuery, have more than 1 form with the same class name

I've tried to search for an answer here but there are no answers that match what I need. I have more than 1 form with class name


<form class='sbt-form'>
<input name='kord' val=1/>

<form class='sbt-form'>
<input name='kord' val=2/>

<form class='sbt-form'>
<input name='kord' val=3/>

When one form is submitted (let's say the third one) I want just to get the value of
element with
name = 'kord'

How do i do this using jQuery?

Answer Source

You can attach a submit handler to the forms and search within them for the element you want to find. Try this:

$('.sbt-form').submit(function(e) {
    e.preventDefault(); // stop the form submission to the server. Comment this if not needed.
    var inputValue = $(this).find('input[name=kord]').val();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download