Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
37
rated 0 times [  43] [ 6]  / answers: 1 / hits: 31771  / 15 Years ago, thu, november 19, 2009, 12:00:00

I have a form in HTML with multiple inputs of type submit:



<form id = myForm1 action=doSomethingImportant/10 class=postLink method=post>
<input type=hidden id=antiCSRF name=antiCSRF value=12345></input>
<input type=submit value=clickThisLink></input>
<input type=submit value=Don'tclickThisLink></input>
</form>


What I want to do is select only the first input with type submit while ignoring the others, the snippet of code I currently have is as follows, note it is within a for-each loop that goes through all forms on my page, hence (this) to avoid confusion:



var name = $(this).find(input[type='submit']).val();


I'm thinking this already grabs the first input of type submit by default, I'm not sure if that assumption is correct or if there's a more formal way of going about it, thanks.


More From » jquery

 Answers
215

Try:



$(this).children(input[type='submit']:first).val();

[#98272] Monday, November 16, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
emerymariamm

Total Points: 276
Total Questions: 97
Total Answers: 99

Location: Comoros
Member since Sun, Dec 13, 2020
4 Years ago
emerymariamm questions
Fri, Mar 4, 22, 00:00, 2 Years ago
Wed, Jan 12, 22, 00:00, 2 Years ago
Sun, Jul 4, 21, 00:00, 3 Years ago
Wed, Dec 23, 20, 00:00, 4 Years ago
;