• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Enter key question .....

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
Given below is the code that I am using to submit a Form (which is actually a JSP) to the server anytime I hit the enter key.
I have a number of checks for each field on the form that I validate using javascript.
When I enter a wrong value into one of the text boxes and hit the enter key, it validates that field and displays an alert box that the format of that field is wrong, but still submits the form to the server.
Could anybody help me with understand why this could be happening?
Chuck
---------------------------------------------------
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");
function keyDown(DnEvents)
{// handles keypress
// determines whether Netscape or Internet Explorer
k = (netscape) ? DnEvents.which : window.event.keyCode;
if (k == 13) {// enter key pressed
submitRequest();
}
}
---------------------------------------------------------
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Chuck
In the onsubmit part of your form tag do this:
<form name=myForm method=whichever onsubmit='return myFunction();'>
Then in your validation function return true if everything is ok, or return false after your alert. Returning false to onsubmit causes the form not to submit.
hope that helps

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic