views:

177

answers:

2

Hello, 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.

+2  A: 

how about the first selector

var name = $("input[type='submit']:first").val();
Marek Karbarz
Hey Zarembisty, tried adding that, but that caused my entire script to stop working.
kingrichard2005
+3  A: 

Try:

$(this).children("input[type='submit']:first").val();
eKek0
Worked great, thanks eKek0
kingrichard2005