Controlling behavior of the Enter key in the form.

A

Amir Hardon

I want to call a JS function when Enter is pressed inside the form,
and when the submit button is clicked I want to submit the form.

Any simple way for doing this?

Thanks,
-Amir.
 
A

Amir Hardon

Amir said:
I want to call a JS function when Enter is pressed inside the form,
and when the submit button is clicked I want to submit the form.

Any simple way for doing this?

Thanks,
-Amir.
Ok, I found a solution:

function chkent(field, event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which :
event.charCode;
if (keyCode == 13) {
jsfunction();
return false;
}
else
return true;
}

<input type="text" onkeypress="return chkent(this, event);">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top