?
Solved

Javascript form submit -- weird problem

Posted on 2011-02-18
4
Medium Priority
?
264 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: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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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

864 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