473,808 Members | 2,852 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

form validation that will display text at top of page if fields are blank

I am looking for a validation script that will only look at the fields in
the cgi form, determine if the fields are filled out, then if one or more
are blank will write a message at the top of the page stating that some
fields have not been filled out. I don't want a pop-up, I just want to send
them back. I had seen something that did this using <div /> tags but cant
seem to find one I can modify to work for this application.

I was using Jennifer Madden's steroid basic validator, but that wont work
for me as it requires all form names to use an asterisk if required as its
field name. This is not supported by the email result builder I am using.

Thanks!
-Matt
Jul 20 '05 #1
3 3332
"Matt Herson" <eb***@mherson. com> writes:
I am looking for a validation script that will only look at the fields in
the cgi form, determine if the fields are filled out, then if one or more
are blank will write a message at the top of the page stating that some
fields have not been filled out. I don't want a pop-up, I just want to send
them back. I had seen something that did this using <div /> tags but cant
seem to find one I can modify to work for this application.


Try something like this:
---
<script type="text/javascript">
function validate(form) {
for (var i = 0; i < form.elements.l ength; i++) {
var elem = form.elements[i];
if (elem.tagName == "INPUT" &&
(elem.type == "text" || elem.type == "password") ||
elem.tagName == "TEXTAREA") {
if (elem.value == "") {return false;}
}
}
return true;
}
function validateAndDisp lay(form,div) {
div = document.getEle mentById(div);
if (!validate(form )) {
div.innerHTML = "Some fields still needs to be filled.";
return false;
} else {
div.innerHTML = "";
return true;
}
}
</script>

<div id="output"></div>
<form action="..." onsubmit="valid ateAndDisplay(t his,'output')">
<input type="text" name="f1">
<input type="password" name="f2">
<textarea name="f3"></textarea>
<input type="submit" value="submit">
</form>
---
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:r8******** **@hotpop.com.. .
"Matt Herson" <eb***@mherson. com> writes:
I am looking for a validation script that will only look at the fields in the cgi form, determine if the fields are filled out, then if one or more are blank will write a message at the top of the page stating that some
fields have not been filled out. I don't want a pop-up, I just want to send them back. I had seen something that did this using <div /> tags but cant seem to find one I can modify to work for this application.


Try something like this:
---
<script type="text/javascript">
function validate(form) {
for (var i = 0; i < form.elements.l ength; i++) {
var elem = form.elements[i];
if (elem.tagName == "INPUT" &&
(elem.type == "text" || elem.type == "password") ||
elem.tagName == "TEXTAREA") {
if (elem.value == "") {return false;}
}
}
return true;
}
function validateAndDisp lay(form,div) {
div = document.getEle mentById(div);
if (!validate(form )) {
div.innerHTML = "Some fields still needs to be filled.";
return false;
} else {
div.innerHTML = "";
return true;
}
}
</script>

<div id="output"></div>
<form action="..." onsubmit="valid ateAndDisplay(t his,'output')">
<input type="text" name="f1">
<input type="password" name="f2">
<textarea name="f3"></textarea>
<input type="submit" value="submit">
</form>
---
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'


Thanks! This script is working fine. Only thing now is I want to return
the entire form contents - not just the missing message. Is this done by
changing placement of the <div> tags or does the script need to be modified?
Thanks!
-Matt
Jul 20 '05 #3

"Matt Herson" <eb***@mherson. com> wrote in message
news:bl******** **@bob.news.rcn .net...

"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:r8******** **@hotpop.com.. .
"Matt Herson" <eb***@mherson. com> writes:
I am looking for a validation script that will only look at the fields in the cgi form, determine if the fields are filled out, then if one or more are blank will write a message at the top of the page stating that some fields have not been filled out. I don't want a pop-up, I just want
to
send them back. I had seen something that did this using <div /> tags but cant seem to find one I can modify to work for this application.
Try something like this:
---
<script type="text/javascript">
function validate(form) {
for (var i = 0; i < form.elements.l ength; i++) {
var elem = form.elements[i];
if (elem.tagName == "INPUT" &&
(elem.type == "text" || elem.type == "password") ||
elem.tagName == "TEXTAREA") {
if (elem.value == "") {return false;}
}
}
return true;
}
function validateAndDisp lay(form,div) {
div = document.getEle mentById(div);
if (!validate(form )) {
div.innerHTML = "Some fields still needs to be filled.";
return false;
} else {
div.innerHTML = "";
return true;
}
}
</script>

<div id="output"></div>
<form action="..." onsubmit="valid ateAndDisplay(t his,'output')">
<input type="text" name="f1">
<input type="password" name="f2">
<textarea name="f3"></textarea>
<input type="submit" value="submit">
</form>
---
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'


Thanks! This script is working fine. Only thing now is I want to return
the entire form contents - not just the missing message. Is this done by
changing placement of the <div> tags or does the script need to be

modified? Thanks!
-Matt

After further review, it looks like the message comes back for all
conditions. Even when the field is filled in. Any ideas?
Jul 20 '05 #4

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

Similar topics

5
4264
by: TG | last post by:
Dear PHP Group, I have two forms that are used to collect user information. The first one takes user inputted values such as fullname, city, address etc. I want these values to display in the second form when it is called. Both forms are .htm files that call themselves when the submit button is press via the following command in each form: <form method="post" action="<?php $server?>">
11
8761
by: Jim | last post by:
Hi, I keep getting form results emailed to me that would indicate a form from my web site is getting submitted with all fields blank or empty, but my code should preventing users from proceeding if they left any field blank. My guess is that someone is trying to hack the site using the form to gain entry or run commands -- I don't really know since I'm not a hacker. I just know that forms are often susceptible to these kinds of...
3
9429
by: Bill | last post by:
Hi. I have a multi-page form where the user enters datails to be submitted to a database on the final page. To move through the pages I have Next and Previous buttons using the following function function nextPage(loc) { validateForm('section'); //checks for blank fields and displays an alert
6
507
by: Darren | last post by:
I have a form that has 10 fields on it. I have made all of them "Required". I also am using vb if statements to decide whether or not each field should be on the page. I am using the vb to compare values in my database and if a certain field equals something then the field is shown on the form. When the form is displayed in the browser, it could any increment of the 10 fields on it. My problem is that unless all fields are being shown...
5
5906
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse button to open the "file browse" dialog and the Submit button to submit the form data.
2
1529
by: geodev | last post by:
Hi, I'm building a web form utilizing ASP.NET and VB.NET. The web form has three pages: 1. The first page has a set of text boxes that a user has to fill out and then hit the next button. Once this is done the form has to resubmits to itself and if all the required data is entered it displays the next page. 2. The second page is another input screen. When the user has completed filling out the required fields on the page the user hits a...
7
7002
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form is correct I need to submit to another page that uses the form data. I first tried making the form submit action= field point to the same file. When the form was correct, I tried loading the next page by using <META http-equiv refresh>. But...
2
3077
ak1dnar
by: ak1dnar | last post by:
Hi, please help me on this. Here i am having a simple form that consist with name and email fields and both are required fields. i am going to validate this inputs using validate.php. but since i am since i am using responseText object i couldn't display the error message for corresponding fields. That means if name is blank error should appers in <span id="output_name"> if email is blank error should appers in <span id="output_email"> ...
7
3625
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
0
9721
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
9600
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,...
1
10374
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
9195
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7651
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6880
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
5547
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
5685
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3011
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.