473,387 Members | 1,456 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,387 software developers and data experts.

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 3314
"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.length; 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 validateAndDisplay(form,div) {
div = document.getElementById(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="validateAndDisplay(this,'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.length; 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 validateAndDisplay(form,div) {
div = document.getElementById(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="validateAndDisplay(this,'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.length; 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 validateAndDisplay(form,div) {
div = document.getElementById(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="validateAndDisplay(this,'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
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...
11
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...
3
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...
6
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...
5
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...
2
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...
7
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...
2
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...
7
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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...

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.