473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Is a submit button pressed in ASP?

31
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 3706
DrBunchman
979 Expert 512MB
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 Expert 256MB
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
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...
8
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...
15
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...
6
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...
4
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...
4
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...
3
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...
3
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"...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.