I have a few textboxes and buttons on a HTML form, say, TextBox1 and
Button1, Button2. The button written before the other will always be
triggerd when ENTER key pressed. I guess this is the default behaviour
of HTML even though I find no documentation confirming it. But what if
I want to have my own choice?
After struggling for 1.5 hours(that's a long time really) and I came
out with this solution,
[script language="javascript"]
document.all.TextBox1.onkeypress=OnButton2Clicked;
function OnButton2Clicked(){
if (event.keyCode==13){
event.keyCode=0;
document.all.Button2.click();
}
}
[/script]
The meat is to set keyCode to zero when ENTER key pressed thus fooled
the form handler.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment