- I am trying to submit a form in PHP using Enter key, it doesn't work here is the code:
I get an error for myform.submit() saying “Object doesn’t support this property or method”
Code: Select all
<head> <script language="Javascript"> function keypress(myform,e){if(e && e.which){ e = e; characterCode = e.which; } else{ e=event; characterCode = e.keyCode; } if(characterCode == 13){ myform.submit(); // return false; } else{ return true; }} </script> </head> <body> <form method="post" name="form1" action="<?php print "$_SERVERїPHP_SELF]";?>"> <center>Please Select a <?php print "$criteria<br><br>" ?> <select name="choice" size="8" Style="width:150px" onkeypress="return keypress(this.form,event)" > </select></center> <input type="submit" name="submit" value="Submit">&nbsp <input type="submit" name="stop" value=" Show Items "> <script language="Javascript"> document.form1.choice.focus();</script> </body>
I changed the call to keypress, as onkeypress =“return keypress(this.form1,event)”
Since my form is named form1, now it gives an error “submit is null or not an object”. - My page loads with the focus on the "Select" object. After I submit my page will reload, and I may get another form similar to the look of the one for which code is given or I may get an output. In either case after submitting, if I press the back button to come back to the previous page, my "Select" object looses focus, and I am unable to use the arrow keys to move. PS: The focus is fine when I load the page for the first time, and even on subsequent submits the new page also has focus on the "Select" object (if that is what is loaded) the only problem comes when I go BACK.
Code: Select all
andCode: Select all
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]