Re: Capturing Enter KeyDown in a TextBox

From: hb (hbranyan.SPAMBLOCK_at_merc.mercer.edu)
Date: 05/20/04


Date: Thu, 20 May 2004 12:44:37 -0400

Think about the value you pass to the function. You are passing the ID of
the btn, so you can't just call btn.click(); - that's the same as saying
'btnCreateNewsFeed'.click() and that will not work.

Instead, replace btn.click(); with document.getElementById(btn).click();

"George Durzi" <gdurzi@hotmail.com> wrote in message
news:eDYCifoPEHA.1036@TK2MSFTNGP09.phx.gbl...
> I have a text box and a button, and I want the enter key to run the click
> event of the button. The textbox and button are inside a user control. I
> tried all sorts of stuff with the __EVENTTARGET hidden field with no luck.
>
> Here's what I'm doing
>
> function KeyDownHandler(btn)
> {
> if (event.keyCode == 13)
> {
> event.returnValue=false;
> event.cancel = true;
> btn.click();
> }
> }
>
> <asp:TextBox ID="txtNewsFeedName" Runat="server" MaxLength="100"
> Columns="35"
onKeyDown="KeyDownHandler('btnCreateNewsFeed')"></asp:TextBox>
> <asp:button ID="btnCreateNewsFeed" Runat="server" Text="Add"
> CssClass="submitbutton" CausesValidation="False"></asp:button>
>
>
>
> When I hit Enter when typing inside the TextBox, the KeyDownHandler
function
> gets executed, but I get an error on the btn.click(); line.
>
> The error is: object doesn't support this property or method.
>
> Verified that btn is coming in as btnCreateNewsFeed. Dunno if you need to
do
> casting in JavaScript, but how is this function supposed to know that this
> is a button...
>
> How can fire the click event of that button?
>
>