473,399 Members | 3,888 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,399 software developers and data experts.

Form submit button

14
Hello, i'm new to HTML

I've created a registration form and have a submit button. i want that if the form is blank and submit is clicked that I could link it to a page saying, "please input information on form" or "don't leave form blank". As it now is, a page comes up saying "page cannot be displayed". this does not explain to the user what they did wrong.

Once there is information on the form when the submit button is clicked, it is linked to a confirmation page....this works fine.

Are there any suggestions as to how i can do this?? thanks so much!
Oct 5 '06 #1
5 3656
r035198x
13,262 8TB
Hello, i'm new to HTML

I've created a registration form and have a submit button. i want that if the form is blank and submit is clicked that I could link it to a page saying, "please input information on form" or "don't leave form blank". As it now is, a page comes up saying "page cannot be displayed". this does not explain to the user what they did wrong.

Once there is information on the form when the submit button is clicked, it is linked to a confirmation page....this works fine.

Are there any suggestions as to how i can do this?? thanks so much!
You validate the form using javascipt. A simple function to validate whether or not a textbox is empty is

Expand|Select|Wrap|Line Numbers
  1. function isEmpty(textbox) {
  2.       if(textbox.value == "") {
  3.     return true;
  4.       }
  5.        else {
  6.           return false;
  7.       }
To use it just call it with the name of the box
eg
Expand|Select|Wrap|Line Numbers
  1. function validateClients(form) {
  2.         if(isEmpty(form.name)) {
  3.     alert("Client creation cannot proceed without name");
  4.     form.name.focus();
  5.     return false;
  6.        }
  7. }
on your form tag just do something like
Expand|Select|Wrap|Line Numbers
  1. <FORM name="myForm" onSubmit = "return validateClientClient(this)">
Oct 5 '06 #2
Nerry
14
You validate the form using javascipt. A simple function to validate whether or not a textbox is empty is

Expand|Select|Wrap|Line Numbers
  1. function isEmpty(textbox) {
  2.       if(textbox.value == "") {
  3.     return true;
  4.       }
  5.        else {
  6.           return false;
  7.       }
To use it just call it with the name of the box
eg
Expand|Select|Wrap|Line Numbers
  1. function validateClients(form) {
  2.         if(isEmpty(form.name)) {
  3.     alert("Client creation cannot proceed without name");
  4.     form.name.focus();
  5.     return false;
  6.        }
  7. }
on your form tag just do something like
Expand|Select|Wrap|Line Numbers
  1. <FORM name="myForm" onSubmit = "return validateClientClient(this)">

Thx r035198x, but i'm still confused, with the code you gave, here's what i did:

<script language="JavaScript" type="text/JavaScript">

function validateClients(form1) {
if(isEmpty(form1.CName)) {
alert("Enter your company's name");
form1.CName.focus();
return false;
}
}
//-->
</script>

Here, form1 – name of the form, CName – is the name of a textbox value in the form, I’m not sure if I wrote the code properly. Where you placed Clients in validateClients, I know it was just an eg. But what does it refer to? Also is there a return true, that’s supposed to be in there somewhere?

I put this script just above the form tag. I was unsure of where to put the script, because there is another script at the top in the <head> of the page.

For the form tag you wrote onSubmit = "return validateClientClient(this)", what does the (this) refer to and is Client supposed to be put twice?

Thx again
Oct 5 '06 #3
r035198x
13,262 8TB
Thx r035198x, but i'm still confused, with the code you gave, here's what i did:

<script language="JavaScript" type="text/JavaScript">

function validateClients(form1) {
if(isEmpty(form1.CName)) {
alert("Enter your company's name");
form1.CName.focus();
return false;
}
}
//-->
</script>

Here, form1 – name of the form, CName – is the name of a textbox value in the form, I’m not sure if I wrote the code properly. Where you placed Clients in validateClients, I know it was just an eg. But what does it refer to? Also is there a return true, that’s supposed to be in there somewhere?

I put this script just above the form tag. I was unsure of where to put the script, because there is another script at the top in the <head> of the page.

For the form tag you wrote onSubmit = "return validateClientClient(this)", what does the (this) refer to and is Client supposed to be put twice?

Thx again

First you can place the functions where you have the other javascripts preferrably in their own script tag as you've already done.
Yes there should be a return true somewhere
Expand|Select|Wrap|Line Numbers
  1. function validateClients(form1) {
  2.         if(isEmpty(form1.CName)) {
  3.     alert("Enter your company's name");
  4.     form1.CName.focus();
  5.     return false;
  6.        }
  7.        return true; // right here
  8. }
for the form tag I made a typing error. You are supposed to call the javascript function validateClients and therefore the name of the function has to match.

Since you put this in a form tag, when you say this, you are referring to this form. You are passing this form as a parameter to the function.

Note this can also refer to the document so that you could also have said this.form1 meaning this documents's form1

When used alone as just this however, it refers to the form.

Accept my apologies for the errors. I've had quite a day at work
Oct 5 '06 #4
Nerry
14
thx but i still had problems with it, so i decided to go with the simple validation you mentioned before:

function isEmpty(textbox) {
if(textbox.value == "") {
return true;
}
else {
return false;
}
}

the code was slightly different:

function validate_form ( )
{
valid = true;
if ( document.form1.CName.value == "" )
{
alert ( "Please enter your 'Company's Name'." );
valid = false;
}
return valid;
}
in form tag - onSubmit="return validate_form ( );"

this suited my purposes, thx again!
Oct 9 '06 #5
r035198x
13,262 8TB
thx but i still had problems with it, so i decided to go with the simple validation you mentioned before:

function isEmpty(textbox) {
if(textbox.value == "") {
return true;
}
else {
return false;
}
}

the code was slightly different:

function validate_form ( )
{
valid = true;
if ( document.form1.CName.value == "" )
{
alert ( "Please enter your 'Company's Name'." );
valid = false;
}
return valid;
}
in form tag - onSubmit="return validate_form ( );"

this suited my purposes, thx again!
Simple enough. You realise of course that you no longer need the isEmpty function.
Oct 9 '06 #6

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

Similar topics

1
by: monika | last post by:
hi ... I have an asp page which has 3 buttons. <p align="center"><input class="button" type="button" onClick="location='welStudent.asp';" value="Click to write a new story"></p> <p...
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...
5
by: rjames.clarke | last post by:
I have the following. $result=mysql_query($sql); $nrows=mysql_num_rows($result); for ($i=0;$i<$nrows;$i++) { $row_array=mysql_fetch_row($result); echo "<form name='testform'...
4
by: Alex Sibilev | last post by:
Hello, I have a really weird problem I've been trying to solve it without any luck for the last couple of hours :( I'm writing a "conference board" application (quite similar to ASP.NET...
16
by: browntown | last post by:
so I have this application I'm nearly finished with. The only thing the client has requested is the ability to submit the form by pressing "enter". I didn't think this would be a huge pain in the...
9
by: Veerle | last post by:
Hi, When you use multiple asp:Buttons on one Form, then asp.net generates html submit buttons for all of them. When you put your cursor in one of the textfields of the form, the default submit...
5
by: plumba | last post by:
Ok, another query.... I have a checkbox at the bottom of my form which when checked unhides a <div> block which displays the submit button. The problem I have is when the clear form button is...
4
by: j1dopeman | last post by:
Hi, I'd like to use a button to save and then submit a form. I can set the onlick of the button to mahButton_click or submit, but I can't figure out how to do both. It looks like c# can't...
13
by: Andrew Falanga | last post by:
HI, Just a warning, I'm a javascript neophyte. I'm writing a function to validate the contents of a form on a web page I'm developing. Since I'm a neophyte, this function is quite simple at...
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
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
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...
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.