Two Events Fired when I press enter key

Hyproberuby

New Member
In my code, I have the following javascript code block in the header section\[code\] function validateForm(bid) { switch (bid) { case "submitIDSearch": alert("submitIDSearch"); return false; case "submitNameSearch": alert("submitNameSearch"); return false; } } function fKeyDown(e) { var kc = window.event ? window.event.keyCode : e.which; if (kc == 13) { document.getElementById('submitNameSearch').click(); } }\[/code\]Then I have the following HTML code block\[code\] <form name="checkAbsenceForm" method="post" action="absenceReport.htm" onsubmit="return validateForm(this.submited)"> <label class="q">ID * <input id="searchRUID" name="searchID" maxlength="9" /></label> <input id="submitIDSearch" type="submit" value="http://stackoverflow.com/questions/12784005/Search ID" onclick="this.form.submited = this.id;" /> <hr /> <label class="q">First Name <input id="searchFirstName" name="searchFirstName" maxlength="23" onKeyDown="javascript:fKeyDown(event);"/></label> <br /> <label class="q">Last Name * <input id="searchLastName" name="searchLastName" maxlength="23" onKeyDown="javascript:fKeyDown(event);" /></label> <input id="submitNameSearch" type="submit" value="http://stackoverflow.com/questions/12784005/Search Name" onclick="this.form.submited = this.id;" /> </form>\[/code\]What happened was that when I press enter key in the searchLastName input text box, both alert message box pops up. One showing submitNameSearch and the other showing submitIDSearch. submitNameSearch is the desired event, but submitIDSearch is not, I think it is somehow triggered by default.May I ask if there's a way to get rid of the submitIDSearch event when I press enter key in the searchLastName input text box?Thanks a lot!
 
Back
Top