Altiano Gerung Altiano Gerung - 25 days ago 6
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();