Reputation: 319
I want my textbox trigger an event through enter and runs a function, here's my input form and pretend the submitting of form is disabled...
<input type="text" name="webURL" value="" id="urlField" onkeypress="enterKey(event){ checkURL(this) }" />
Now after inputting something on text box, and enter was triggered by this enter event verification below:
function enterKey(e){
var keycode = e.which ? e.which : e.keyCode;
if(keycode == 13){
return true;
}
return false;
}
Whenever it verifies that the user trigger enter it returns true otherwise false. I think i'm messing something on the input form keypress
function. Anyone can tell me how to do that to make it work and run the checkURL()
function?
Upvotes: 0
Views: 224
Reputation: 8814
onkeypress="if(enterKey(event)){ checkURL(this) }"
But it's a better practice separate js from markup. Using a js frameworks, such as jQuery, helps a lot..
Upvotes: 2