Javascript form submit -- weird problem

Hi ,
i am trying to submit a form using javascript on pressing EnterKey from a textbox.
<input type="text" name="txtdate" id="txtdate" size="10px" onkeydown="javascript:txtdate_submit(event);" >

<input type="submit" name="btnsubmit" id="btnsubmit" value="Get Report">
works fine if i use the alert message in javascript ....else if i comment alert("after") .. form doesnt get submitted as 'submit' button click.

Environment: ASP, JavaScript,HTML

function txtdate_submit(e)
if(e.keyCode==13) { 

Open in new window

Who is Participating?
Gurvinder Pal SinghConnect With a Mentor Commented:
not sure, but it seems that when you capture the keycode, then unless you do return true, it returns fale by default, which cancels the enter key press
Gurvinder Pal SinghCommented:
why do you want to click the submit button to submit form, you could have simply done this by
document.forms[0].submit(); \\replace line with 6

kishan66Author Commented:
Hi, gurvinder,

reason for using ->  ASP page looks for the source of the form submit... Ex: whether its from "Submit button" or from some other source.

i also agree with you. i can always use different approaches .

But just curious to know  'Y'   does it fail in above mentioned condition . What does alert() message has to do with form submit. Does alert create some delay ...If Yes, is delay really required?

would appreciate if some one gives me better information.
Michel PlungjanIT ExpertCommented:
If you only have one text field and a submit you do not need to test the enter. Enter will submit

Also look into onkeyup and onkeypress
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.