473,765 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is a submit button pressed in ASP?

31 New Member
Hi,

I have 2 text box and a "search " button.

I would like to check if the text boxes are empty [u]when the search button has been pressed. How should I do that?

Regards,
FF
Jun 9 '08 #1
2 3721
DrBunchman
979 Recognized Expert Contributor
Hi,

I have 2 text box and a "search " button.

I would like to check if the text boxes are empty [u]when the search button has been pressed. How should I do that?

Regards,
FF
Hi FF,

You need to use a bit of javascript to check the contents of the textboxes prior to the form being submitted. First place a javascript function between the head tags of your page which contains the validation then call that function in the onclick event of your submit button. Use this example to help you:

Expand|Select|Wrap|Line Numbers
  1.  <head> 
  2. <script type="text/javascript">
  3. function Val()
  4. {
  5. var txt1 = document.Form1.Textbox1.Value;
  6. if (txt1 == '')
  7. {
  8. return false;
  9. }
  10. else
  11. {
  12. return true;
  13. }
  14. }
  15. </script>
  16. </head>
  17. <body>
  18. <form name="Form1">
  19. <input type="text" name="TextBox1" />
  20. <input type="submit" onclick="return Val();" />
  21. </form>
  22. </body>
  23.  
Hope this helps.

Dr B
Jun 9 '08 #2
jeffstl
432 Recognized Expert Contributor
What I'm posting here is not exactly a great solution necessarily (javascript is definitly ideal in terms of a users experience and programing logic) but as an additional option or alternative if you don't want to mess with javascript or you need more flexibility with error messages, etc you can check if the boxes are empty on your submit page and redirect them back to the original page if they are empty.

So your submit page would have (assuming BOTH text boxes are blank when you send them back:

Expand|Select|Wrap|Line Numbers
  1.  
  2. dim FirstText, SecondText
  3.  
  4. FirstText = request.form("txtBox1")
  5. SecondText = request.form("txtBox2")
  6.  
  7. If FirstText = "" then
  8.      If SecondText = "" then 'send them back
  9.           resposnse.redirect("SearchPage.asp?err=Blanks")
  10.      end if
  11. end if
  12.  
  13.  
Then on your original search page you use the err variable to display a message

Expand|Select|Wrap|Line Numbers
  1.  
  2. if request.querystring("err") <> "" then
  3.      response.write "Fields cannot be blank!!"
  4. end if
  5.  
  6.  
To go a step further for anyone else too, you can pass your user filled data back and forth either in session objects or querystrings if you want to be able to retain the data the user entered on the search page (ie return them to the page with the form filled out rather then clearing it out again)
Jun 9 '08 #3

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

Similar topics

2
41059
by: jb | last post by:
Hello, I need to know which button was pressed in the submit , i tried reading the vaule of submit it the validateDate function but it returns 'undefined' value ; I do this in asp all the time, Not sure how to do it in javascript <form name="form1" method="post" action="myNewplace.asp" ONSUBMIT="return ValidateData();"> <input type="Submit" name="Submit" value="Save" >
8
14647
by: Syed Ali | last post by:
Hello, I have 1 HTML form with 4 submit buttons and 10 textfield entry areas. If submit button1 is pressed I need to make sure that all 10 textfield entries have been filled before submitting the form. If submit button2 is pressed I need to make sure that only textfied1 is filled before submitting the form.
15
6576
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and the buttons. The problem is when I post a form to itself, the Enter key will not submit the form, it only clears the contents of the text box. The only way I can submit is to click the submit button. Here is a simplified version of my code that I...
6
3106
by: CJM | last post by:
Can somebody clarify if/how/when a simple form is submitted when the <Enter> key is pressed? As I understood it, if you have a form with a single submit button, if enter is pressed, the form should be submitted as if the button is pressed. Is this correct? Does this behaviour vary across browsers? Chris
4
4134
by: actionwoman63 | last post by:
Dear all I need to be able to check which one out of two submit buttons within the same form was pressed in a javascript function prior to form submission. And before I get flamed for not finding the answer in previous posts - I have already seen this question answered numerous times in this forum, only problem is that the recommended method is not available to me :-(. I know that if I could code an onclick event on the <input...
4
9904
by: karenmiddleol | last post by:
I have the following form the user enters the From and to period and presses the Submit button and the form fields are cleared once the submit button is pressed. Is there a way I can keep the Form fields visible and not cleared. Also when I display the message I want the original form cleared in a different version of this page how can I clear the form completely when I display the data entered from the Response statements I do not...
3
2603
by: Arun K | last post by:
Hi, I am creating a simple .aspx page to add some fields with validation. I have used different .NET validations like REquiredFieldValidator, RegularExpressionValidator and showed the summary in the bulleted list on top. I have 3 text boxes, and two RadioButtonList. and 3 buttons. One for Submit, Reset and Exit. If submit is pressed page should be validated and submit (insert into
3
2500
by: Daniel | last post by:
Hi all, I am using .NET 1.1. I have a form with a cancel button, something like this: <form method="post"....> <input type="submit" value="Submit"> <input type="submit" value="Cancel" id="btnCancel"> </form>
1
6259
by: abcdriver | last post by:
Later edit: Too complex: The only thing I should know is: The submit button's NAME (and value) will only be sent if that particular button was used to submit the form, so you should be able to check that in the server side script. Rest is history:
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
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
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
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
6649
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
5277
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
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

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.