473,320 Members | 1,969 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,320 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 3705
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.