By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,566 Members | 1,779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,566 IT Pros & Developers. It's quick & easy.

validate and then Submit ASP page on pressing ENTER button

Soniad
P: 66
Hello,


I am having ASP page, in this there in one textbox to enter emailid ,I have done javascript validation for this i.e. if email id is not valid then alert message is shown and page will not be submitted.
all this is working properly on "OnClick" event .
but when the function is called "onkeypress" then alert message is shown if email id is invalid,but the page gets submitted after clicking on OK of alert message or entering on alert message

Here's javascript code :
Expand|Select|Wrap|Line Numbers
  1. var AccOk 
  2. AccOk = "yes"
  3.  
  4. function fncheck()
  5. {  
  6.         if (document.frmAccCheck.txtloginid.value=="")
  7.         {
  8.         AccOk = "no";
  9.         alert("Please Enter EmailId");
  10.         document.frmAccCheck.txtloginid.focus()
  11.         }
  12.         else if(document.frmAccCheck.txtloginid.value!="")
  13.         {
  14.          if (document.frmAccCheck.txtloginid.value.indexOf(".") == -1 || document.frmAccCheck.txtloginid.value.indexOf("@") == -1)
  15.          {
  16.           AccOk = "no";
  17.           alert("Please Enter Valid EmailId");
  18.           document.frmAccCheck.txtloginid.focus()
  19.          }
  20.         }
  21.  
  22.         if (AccOk == "yes")
  23.         {
  24.         alert("submit")
  25.         document.frmAccCheck.hidsubmit.value = "Check";
  26.         document.frmAccCheck.method = "post";
  27.         document.frmAccCheck.action = "AccountInterface.asp";
  28.         document.frmAccCheck.submit();
  29.         }
  30.  
  31. }
  32.  
  33.  
  34. function fnlogin()
  35. {
  36.  
  37.     if ( window.event.keyCode == 13)
  38.     {  alert("testlogin")        
  39.         fncheck()
  40.     }
  41. }
Here's ASP control with onkeypress event :
Expand|Select|Wrap|Line Numbers
  1.  <input type="text" name="txtloginid" onKeyPress="javascript:fnlogin();">

page should not get submitted .


Regards,
"D"
Mar 8 '09 #1
Share this Question
Share on Google+
2 Replies


jhardman
Expert 2.5K+
P: 3,405
You could do this with ASP by posting to the same page and redisplaying the same form (with the inputs filled in where applicable), but it sounds like you are taking a javascript approach, I'll move it over to the javascript forum for you.

Jared
Mar 9 '09 #2

Dormilich
Expert Mod 5K+
P: 8,639
to suppress form submission from the HTML side (which is in most cases also triggerd, when you press enter) you need to do
Expand|Select|Wrap|Line Numbers
  1. <form action="..." onsubmit="return false;" ... >
you can also let Javascript decide, whether to submit (of cause checkUserInput() must return true or false)
Expand|Select|Wrap|Line Numbers
  1. <form action="..." onsubmit="return checkUserInput();" ... >
Mar 9 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.