Solved

Javascript form submit -- weird problem

Posted on 2011-02-18
4
258 Views
Last Modified: 2012-05-11
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



----JavaScript---
function txtdate_submit(e)
{
	
if(e.keyCode==13) { 
  document.getElementById("btnsubmit").click();		
  alert("after");		
	}
}

Open in new window

0
Comment
Question by:kishan66
  • 2
4 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34929146
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

0
 

Author Comment

by:kishan66
ID: 34929290
Hi, gurvinder,

reason for using JavaScript..Button.click() ->  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.
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 34929305
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
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 34929461
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
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question