   How to make Enter key do the same thing as submit button?
  <form><table><tr><td>name:</td><td><input type="text" id="txt1" size=10></td></tr><tr><td></td><td><input type="button" value="submit" onclick="button_1()"></td></tr></table></form>The form calls the button_1() function when I click submit.How do I make it so it also calls this function if the user presses enter while the focus is in the first text field?   
  I assume the question is more related to performing some JavaScript action when submitting the form, not specifically handling pressing enter in a text field. You can do this with the form's onsubmit event. In your case you should probably also change your button into a submit rather than button input field.<form onsubmit="return button_1();">    <table>   <tr>  <td>name:</td><td><input type="text" id="txt1" size="10"></td>   </tr>   <tr>  <td></td>  <td><input type="submit" value="submit"></td>   </tr>    </table></form>Note that if you use "return some_value;" in an onsomething handler you can prevent it from performing its action (in this case, returning false from button_1() would prevent the form from being submitted normally, but returning true would let it submit as normal).   ;  That didn't work. It made it so when I hit enter in the text box, the error message "bad login info" appears briefly then disapears. It's almost like it's doing some rapid page load or something?<html><head><script type="text/javascript">function button_1(){url = "process_login.php?name=" + document.getElementById('txt1').value;xmlhttp = GetXmlHttpObject();xmlhttp.onreadystatechange=stateChanged;xmlhttp.open("GET", url, true);xmlhttp.send(null);}function stateChanged(){if (xmlhttp.readyState==4){if(xmlhttp.responseText){//here goes the redirect codewindow.location='success.php';}else document.getElementById("result").innerHTML="bad login info";}}function GetXmlHttpObject(){if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safarireturn new XMLHttpRequest();}if (window.ActiveXObject){// code for IE6, IE5return new ActiveXObject("Microsoft.XMLHTTP");}return null;}</script></head><body><form onsubmit="button_1()"><table><tr><td>name:</td><td><input type="text" id="txt1" size=10></td></tr><tr><td></td><td><input type="button" value="submit" onclick="button_1()"></td></tr></table></form><div id = "result"></div></body></html>;  You need to return false from your onsubmit handler, to prevent the browser from submitting the form as it normally would do.   ;  By the gods, that did it. I added 'return false;' to the end of function button_1(), and added an 'onsubmit = "return button_1()"' attribute to my form tag. I do find it somewhat strange that i had to return it in the onsubmit instead of just calling it. I guess I'm not 100% clear on how function calls from an html tag really work. May Allah bless your family for a hundred generations and smite your enemies.   