?
Solved

Javascript form submit -- weird problem

Posted on 2011-02-18
4
Medium Priority
?
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
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:
Gurvinder Pal Singh earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

765 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