Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two Submit Buttons Issue --

I have two submit buttons in one form and both the submit are linked to one text box. Is there a way to select a specific "submit" button when enter(on Keyboard) is pressed.

my html:

<form id="myForm" method="post">
id: 
<input type="text" name="id" id="id"/>
<div id="hidden" style="display: none;">
<label>Age:</label>
<input type="text" name="Age"/><br/>
<input type="submit" id="button2" value="Update"/>
</div> 
<input type="submit" id="button1" value ="Get Info" onclick="document.getElementById('hidden').style.display = ''; this.style.display = 'none'"/> 

Small Explanation of the code: Initially all the part will be hidden except one submit("Get Info") and id field. After user enters id and click submit("Get Info") all other fields will appear and the previous submit("Get Info") will be hidden.

like image 223
Ross Taylor Avatar asked Jun 07 '26 22:06

Ross Taylor


1 Answers

Without getting into the JavaScript necessary to make this happen, the submit button that a form uses is defined in the spec.

Essentially the form will use the first enabled submit button that it contains for implicit submission.

Really, what it sounds like you want to do is add an onsubmit handler to the form and prevent the default action (so you can show the rest of the form). In the event handler, you simply need to remove the event handler from the form so that the subsequent call to submit the form will be sent correctly.

like image 136
zzzzBov Avatar answered Jun 10 '26 12:06

zzzzBov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!