sree
sree

Reputation: 902

get input field value in submitted form

I have multiple forms with the same name.

<form name="testFrom" action="/test" method="post">
<input name ="value1" type="text" />
<input type =submit/>

the same form is place in different areas of the page. When I click on submit.

I am calling below function

checkdata(form){

var value1 = $('form[name="testForm"] :input[type=text]').val();
alert(value1)
}

so the value1 is not consistent as we have other forms with the same name and fields values is returning from other forms.

How can get the value from submited form?

Upvotes: 0

Views: 56

Answers (2)

aelor
aelor

Reputation: 11116

put the form in a div and add a id, you can directly add ids to forms but in your case I understand that the forms are generated dynamically.

then you can simply use the selector to find the form inside a particular div.

with an id on form you can:

var value1 = $('form[name="testForm"] :input[type=text]').val();

with id on a div which contains the form.

var value1 = $('#form1 :input[type=text]').val();

Upvotes: 1

Arun P Johny
Arun P Johny

Reputation: 388396

Since the method seems to receive the form as a param try

function checkdata(form) {
    var value1 = $(form).find('input[type=text]').val();
    alert(value1)
}

Upvotes: 0

Related Questions