Solved

Javascript form submit -- weird problem

Posted on 2011-02-18
4
256 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now