Hi, I executed ur code and found that on pressing enter ur function mykeydown() gets called twice.Instead of submitting on enter try to submit the page on any other key it will get printed once. replace the if block in mykeydown() to the following if (whichkey==32) //32 is for spacebar { alert("inside submit1"); document.thisform.action="cal.jsp"; document.thisform.submit(); }
On Tue, 09 Nov 2004 Zaid Ashfaq Ansari wrote : >Hi Edward, >just 1 thing in my mind that can cause this. >whenever a form contains only one element it calls submit automatically on >the click of enter while focus is in that element, so you may not need to >use onkeydown="mykeydown()" but i think this is the behavor of IE only so if >you want other browsers so you will need to check the browser inside your >function. > >Zaid Ansari >[EMAIL PROTECTED] > > > >-----Original Message----- > From: A mailing list about Java Server Pages specification and reference >[mailto:[EMAIL PROTECTED] Behalf Of Martin Gainty >Sent: Monday, November 08, 2004 8:30 AM >To: [EMAIL PROTECTED] >Subject: Re: Why my jsp page is submit twice? > > >Combine the functions >I dont understand why you have <a href="SomeLogic" when you are already >handling the same conditions in mykeydown? >Martin- >----- Original Message ----- > From: "Edward King" <[EMAIL PROTECTED]> >To: <[EMAIL PROTECTED]> >Sent: Friday, November 05, 2004 3:27 AM >Subject: Why my jsp page is submit twice? > > > > I have two JSP page, there are one text and one button in index.jsp,when >write some information in text area and press Enter Key,this page will be >submit to other JSP page named cal.jsp,and in cal.jsp will print a message >"receive".when I run this index.jsp,and write some information in textarea >and then press Enter Key,I found this page is submit to cal.jsp,but I found >that cal.jsp print two receive,like follows: > > receive > > receive > > > > It should print "receive" once,but in fact it prints "receive" twice,why >occur this condition? I only submit once. > > My code is follows: > > > > index.jsp > > ... > > <script language="JavaScript"> > > <!-- > > function onCheck(){ > > if(strIsNull(document.thisform.code.value)==true){ > > alert("can't null"); > > return; > > } > > else{ > > document.thisform.action="cal.jsp"; > > document.thisform.submit(); > > } > > } > > > > function mykeydown() { > > var whichkey=event.keyCode; > > if (whichkey==13 || whichkey==10){ > > document.thisform.action="cal.jsp"; > > document.thisform.submit(); > > } > > } > > --> > > </script> > > <form form name="thisform" method="post"> > > <input name="code" type="text" size="18" onkeydown="mykeydown()"> > > <a href="javascript:onCheck();"><img src="images/queding.gif" width="46" >height="19" border="0"></a> > > </form> > > ... > > > > > > cal.jsp > > ... > > <% > > System.out.println("receive"); > > %> > > > > Any idea will be appreciated! > > Best regards, > > Edward > > > > > > > > > > > > > > >=========================================================================== > > To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff >JSP-INTEREST". > > For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST >DIGEST". > > > > Some relevant archives, FAQs and Forums on JSPs can be found at: > > > > http://java.sun.com/products/jsp > > http://archives.java.sun.com/jsp-interest.html > > http://forums.java.sun.com > > http://www.jspinsider.com > > > >=========================================================================== >To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff >JSP-INTEREST". >For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST >DIGEST". > >Some relevant archives, FAQs and Forums on JSPs can be found at: > > http://java.sun.com/products/jsp > http://archives.java.sun.com/jsp-interest.html > http://forums.java.sun.com > http://www.jspinsider.com > >=========================================================================== >To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". >For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". > >Some relevant archives, FAQs and Forums on JSPs can be found at: > > http://java.sun.com/products/jsp > http://archives.java.sun.com/jsp-interest.html > http://forums.java.sun.com > http://www.jspinsider.com =========================================================================== To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST". For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST". Some relevant archives, FAQs and Forums on JSPs can be found at: http://java.sun.com/products/jsp http://archives.java.sun.com/jsp-interest.html http://forums.java.sun.com http://www.jspinsider.com