Re: javascript doesn't work with my button
- From: "bruce barker \(sqlwork.com\)" <b_r_u_c_e_removeunderscores@xxxxxxxxxxx>
- Date: Thu, 27 Apr 2006 09:18:39 -0700
the browsers default behavior is to submit a form on enter. it picks the
first submit (or the one with the focus) to send as the "clicked" button.
catching the keypress on the button will ony catch a return if the button
has the focus when the enter is pressed. you need to catch keypress at the
body level.
<body onkeypress="handleEnter(event)">
-- bruce (sqlwork.com)
"CharlesA" <CharlesA@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:055A42B8-D45A-4B7C-B7E9-1BB50DF81029@xxxxxxxxxxxxxxxx
Thanks Marina....
that's a good point, however I did mention that the event wasn't firing at
all.
so the problem starts before the content of the javascript
I knew this because I'd put an alert() in there and it never fired off...
this was the javaScript
function handleEnter (field, event) {
altert("You are in event code");
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which :
event.charCode;
if (keyCode == 13) {
var i;
for (i = 0; i < field.form.elements.length; i++)
if (field == field.form.elements[i])
break;
i = (i + 1) % field.form.elements.length;
field.form.elements[i].focus();
return false;
}
else
return true;
}
and this was the way I attached it to the button
btnRole.Attributes.Add("onKeyPress","return handleEnter(this, event);");
then I thought , hey presumably the button doesn't have an onKeypress
event
so I did this:
btnRole.Attributes.Add("onClick","return handleEnter(this, event);");
and then it occured to me hey maybe onClick doesn't trap any key
information
I'm flummoxed
Regards and thanks,
CharlesA
.
- References:
- Re: javascript doesn't work with my button
- From: Marina Levit [MVP]
- Re: javascript doesn't work with my button
- Prev by Date: Re: Button Click and JavaScript
- Next by Date: Re: FormView, SqlDataSource and handling exceptions
- Previous by thread: Re: javascript doesn't work with my button
- Next by thread: NAnt for .net 2.0
- Index(es):