473,788 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

validate and then Submit ASP page on pressing ENTER button

Soniad
66 New Member
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
2 5134
jhardman
3,406 Recognized Expert Specialist
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
8,658 Recognized Expert Moderator Expert
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

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

Similar topics

1
10515
by: jrefactors | last post by:
When the user type something in text box, and press enter, it will submit the form data to test2.jsp, even without pressing submit form button. This is not what I want, I want to submit the form only when the user press the submit button. Any workarounds? Please advise. thanks!! <script type="text/javascript">
4
4357
by: Alonso | last post by:
Hello everybody! :-D I am trying to validate a select object in a form. It does not work fine in Explorer 6.0 because it always send the form, but in Netscape 7.0 it works really fine. The code is below: //---------------------------------------------------------------------- <head> <script > function validate()
2
2007
by: Neo | last post by:
I think the ENTER key worked this way (in the classic ASP days): When the end user presss ENTER, IE will submit the page by 'simulating' a click on the first submit button (or image). On the server side, I will get Len(Request.Form("btnDoSave")) > 0 if that first button is named btnDoSave. But, from a version I am not sure, IE began to loose this feature. How can I work around this?
11
2126
by: wolf | last post by:
There are three webcontrol on my asp.net form: a TextBox, a submit button and a RegularExpressionValidator. And I had set ControlToValidate property of the RegularExpressionValidator to the TextBox. But now, when I input a string in the textbox and press Enter key, the form was submit without client javascript validate. Why? And what should I do to enable client validate before submit the form whethe press Enter key or click Submit...
0
1168
by: Wysiwyg | last post by:
Hi, I just thought I'd post this since I didn't see anyone else doing it this way. I wanted to be able to force the enter key to submit the form without manually changing the html form, In my custom base page class I added a generic method I can call to handle the user pressing the enter key when I want it to submit the form. This sets the destination button on a for the entire form rather than on a field-by-field basis; i.e. it's not...
10
3061
by: Perry van Kuppeveld | last post by:
Hi, I have a problem with formatting a table including text fields wich can contain up to 255 chars. I need a table with 3 columns: - First column 50 % over the with a rowspan of the total number of rows. - Second column 25 %, no rowspan - Third column 25 %, no rowspan
11
8195
by: TokyoJ | last post by:
I run a small camp in Alaska for kids and my director is asking for a web form. Could someone please have a look and offer some advice on where I'm making mistake(s)? I'm using the RegExp function to validate 3 types of fields: text, radio button, dropdown menu. but the code doesn't validate. After 2 days, it's time I asked for guidence. Criteria: Text: only alphabet, no numerals, allowed Radio: one must be selected, Dropdown: an option...
3
1285
by: Chinnala | last post by:
All, I have a "Search" button and "Cancel" button on a web page. When I hit enter, the "Cancel" button receives the focus and btnCancel event is fired. But I want the search button event to be fired when I click enter ? How can I implement this? Appreciate your replies. Thanks, Chinnala.
24
8447
by: MichaelK | last post by:
Who knows how to prevent submitting a form on the press Enter button before all fields on the form are filled up. People just enter the first field hit Enter and it submits the form and doing validation, of course flushing with the bunch of messages because rest of the fields are empty. I remember I had some pages where wrote the code to go on the next field when pressed the Enter button (Tab like), because it didn't go anywhere at all....
0
9498
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10364
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9967
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.