473,549 Members | 2,408 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data Validation Help When Submitting a Form

Hello,

I'm having trouble with submitting my form when checking to see if data
is present in the user-inputted fields. What I want to happen is for
the user to input various pieces of data, submit the form, and then
have a javascript function that checks to see if data is entered, and
if not, have an alert window tell the user which field to enter data
into and then revert back to that same page. If all data is entered,
it would submit the form and send the user to another page. However,
I'm having trouble with reverting back to the orginal page for the user
to update fields to. Here is my code for all other working parts:

<html>
<head>
<script type="text/javascript">

function main(form)
{
if(form.descrip tion.value =='')
{
alert("you have not entered in a description");
}
if(form.awardda te.value =='')
{
alert("you have not entered in an award date");
}
}
</SCRIPT>
</head>
<body>
<form name="input" action="submit. html" method="post">
<table>
Rick's Test Page</th><br><br>
<tr>
<td>Description :<td><input type=text name="descripti on" id=1>
</tr><tr>
<td>Award Date:<td><input type=text name="awarddate " id=2>
</tr>
</table>
<input type="submit" class="FormText " value="submit"
onClick="main(i nput)">
</form>
</body>
</html>

Any ideas?...Thanks !

Rick

Oct 24 '05 #1
4 2281
"Rick" <RS********@gma il.com> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
Hello,

I'm having trouble with submitting my form when checking to see if data
is present in the user-inputted fields. What I want to happen is for
the user to input various pieces of data, submit the form, and then
have a javascript function that checks to see if data is entered, and
if not, have an alert window tell the user which field to enter data
into and then revert back to that same page. If all data is entered,
it would submit the form and send the user to another page. However,
I'm having trouble with reverting back to the orginal page for the user
to update fields to. Here is my code for all other working parts:


[snip]

Will this help? Watch for word-wrap.

<html>
<head>
<script type="text/javascript">
function main(form) {
if (form.descripti on.value =='') {
alert("'Descrip tion' is missing.");
return false;
} else if (form.awarddate .value =='') {
alert("'Award Date' is missing.");
return false;
}
return true;
}
</script>
</head>
<body>
<form action="submit. html" method="post"
name="input" onsubmit="retur n main(this)">
<table>
<tr>
<th colspan="2">Ric k's Test Page<br><br></th>
</tr>
<tr>
<td>Description : <input type="text" name="descripti on"></td>
</tr>
<tr>
<td>Award Date: <input type="text" name="awarddate "></td>
</tr>
</table>
<br><br>
<input type="submit" value="Submit" class="FormText ">
</form>
</body>
</html>
Oct 24 '05 #2
Rick wrote on 24 okt 2005 in comp.lang.javas cript:
Hello,

I'm having trouble with submitting my form when checking to see if data
is present in the user-inputted fields. What I want to happen is for
the user to input various pieces of data, submit the form, and then
have a javascript function that checks to see if data is entered, and
if not, have an alert window tell the user which field to enter data
into and then revert back to that same page. If all data is entered,
it would submit the form and send the user to another page. However,
I'm having trouble with reverting back to the orginal page for the user
to update fields to. Here is my code for all other working parts:

<html>
<head>
<script type="text/javascript">

function main(form)
do not use a reserved name as a variable
{
if(form.descrip tion.value =='')
{
alert("you have not entered in a description");
}
if(form.awardda te.value =='')
{
alert("you have not entered in an award date");
}
}
</SCRIPT>
give a return false if the form should not be submitted yet
</head>
<body>
<form name="input" action="submit. html" method="post">
put asn onsubmit here
<table>
Rick's Test Page</th><br><br>
<tr>
<td>Description :<td><input type=text name="descripti on" id=1>
</tr><tr>
<td>Award Date:<td><input type=text name="awarddate " id=2>
</tr>
</table>
<input type="submit" class="FormText " value="submit"
onClick="main(i nput)">
if the fields are submitted by giving enter the main() will not be
invoked
</form>
</body>
</html>


Try this lean code,
that will only submit if both input fields are filled:
<html>
<head>

<script type="text/javascript">

function main(x) {
var alertstring = '';
if(x.descriptio n.value =='')
alertstring = 'you have not entered in a description.';
if(x.awarddate. value ==''){
alertstring += '\nyou have not entered in an award date.';

if (alertstring != ''){
alert(alertstri ng + '\nI need both fields filled!');
return false;
}
return true;
};

</script>

</head>
<body>

<form action="submit. html" method="post"
onsubmit="retur n main(this)">

Description: <input name="descripti on">
<br>
Award Date: <input name="awarddate ">
<br>
<input type="submit" value="Submit me">
</form>

</body>
</html>

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Oct 24 '05 #3
Thanks everybody,

Code works great now!

Rick

Oct 24 '05 #4
Thanks everybody,

Code works great now!

Rick

Oct 24 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2598
by: Tim Meagher | last post by:
I am trying to use both validation controls and to add submit button attributes, but when I add the button attributes, the javascript fpr the validation controls is no longer created for the page. How can I use both? Thank you, Tim Meagher
4
4492
by: earwicker | last post by:
I recently deployed a web application which contains a user registration form with the usual fields: name, address, email, password, etc. Each of the TextBoxes uses a validation control to verify the input. On my development server, this form works precisely as expected. When I deploy the app to the production server (a hosting service), the...
1
1965
by: Johnny | last post by:
Hello, I've read somewhere that you can validate form data before actually submitting it, similar to what validation controls would do. For example, I have a form that has 2 textboxes. I populate the 2 textboxes with values from the database. I also have an update button that will update the values. If I have not made any change to the...
1
1432
by: Simon | last post by:
Hi, Has anyone experienced the problem where validation controls stop a previously working page from submitting. Sometimes, when I move between my work machine and my home machine validation that was previously working perfectly just starts to bugger up the page. One normally happens is I'll have it working fine at work and then when I
3
2085
by: Saket Mundra | last post by:
I have multiple web forms in my application. The user after logging on is directed to form1 where he enters information desired. Once finished he is directed to form2 and the same procedure goes on till form6. After user has entered information in all 6 forms the information needs to be entered in the database by performing a Transaction. If...
5
1915
by: Sun Jian | last post by:
Hi, I am trying to customize the asp.net validation to achieve the following: Upon submitting the form, client side validation will run, and it will stop at the first error detected. For example if both UserID and Password text fields are required but neither is filled in, I'd like to display the error message (a dialogbox) "Please enter...
3
3571
by: Remy | last post by:
Here is the situation: I have an ASP.NET 2.0 page with 2 panel. Each has a few textboxes and one DefaultButton. All textboxes have one or more Validator. Now everything works fine if I fill everything out correctly and then press the Enter Key, but if the validation fails and I fix the entry and press enter again, nothing happens anymore. ...
19
248046
Atli
by: Atli | last post by:
Introduction At some point, all web developers will need to collect data from their users. In a dynamic web page, everything revolves around the users input, so knowing how to ask for and collect this data is essential to any developer. This article is a basic tutorial on how to user HTML Forms, the most common method of data collection. ...
2
1728
by: plumba | last post by:
Ok, another problem... A bit querky this one.. My form calls an onsubmit function to check fields for completion (validation check). Here is a breakdown version of the form: <html> <script> function toggle_display() { var form = document.getElementById('hidesubmit');
0
7736
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. ...
0
7982
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...
1
7500
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...
0
7827
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...
0
6066
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...
0
3514
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...
0
3494
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1079
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
783
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...

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.