473,405 Members | 2,141 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,405 software developers and data experts.

need: eagle eye to check form validation!

Hi Folks,

i'm newbie at JS; but "learning by tweaking" is my middle name!

Trying to set up a link partnership application on a client's site; got this
script at "The Javascript Source", but it does not work for me.

If anyone would be so kind as to comb it for apparent flaws, I would be
greatly indebted!
My <form> statement includes the following:... onSubmit="return
checkFields();"
=================BEGIN SCRIPT==============

<SCRIPT language="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function checkFields() {
missinginfo = "";
if (document.form1.name.value == "") {
missinginfo += "\n - Name";
}

if (document.form1.website.value == "") {
missinginfo += "\n - Website Name";
}
if (document.form1.links_URL.value == "") {
missinginfo += "\n - URL of your LINKS PAGE";
}

if ((document.form1.URL.value == "") ||
(document.form1.URL.value.indexOf("http://") == -1) ||
(document.form1.URL.value.indexOf(".") == -1)) {
missinginfo += "\n - URL of your Web site";
}

if ((document.form1.links_URL.value == "") ||
(document.form1.links_URL.value.indexOf("http://") == -1) ||
(document.form1.links_URL.value.indexOf(".") == -1)) {
missinginfo += "\n - URL of your LINKS PAGE";
}

if(document.form1.Description.value == "") {
missinginfo += "\n - Description of your Site";
}
if ((document.form1.email.value == "") ||
(document.form1.email.value.indexOf('@') == -1) ||
(document.form1.email.value.indexOf('.') == -1)) {
missinginfo += "\n - Email Address";
}
if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You failed to correctly fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
alert(missinginfo);
return false;
}
else return true;
}
// End -->
</script>
======================END SCRIPT===================
Jul 23 '05 #1
2 1826
If you can give us the URL it would help debugging. The script looks
fine to me. Important is to note that JavaScript is casesensetive. Maybe
'description' should be all small caps or so.

Vincent

Axel Foley wrote:
Hi Folks,

i'm newbie at JS; but "learning by tweaking" is my middle name!

Trying to set up a link partnership application on a client's site; got this
script at "The Javascript Source", but it does not work for me.

If anyone would be so kind as to comb it for apparent flaws, I would be
greatly indebted!
My <form> statement includes the following:... onSubmit="return
checkFields();"


Jul 23 '05 #2
"Axel Foley" <de*******@synchkat.com> writes:
i'm newbie at JS; but "learning by tweaking" is my middle name!

Trying to set up a link partnership application on a client's site; got this
script at "The Javascript Source", but it does not work for me.
"Does not work" is not a very good bug report. It's actually about the
worst that still qualify as reporting a bug.

To report a bug, you should give enough information for us to:
1: reproduce the bug. That is, show the entire page that exhibits the
bug, as well as specify the browser and other runtime environment
details.
Instead of posting an entire page, it's best to first reduce the
page to a small self-contained example that still exhibits the bug.
In many cases, that process will let you discover the bug yourself.
2: recognize the bug. We can run the page all day, but unless the bug
is as blatant as a syntax error, it's likely that we won't know
correct behavior from incorrect, because you haven't described
the correct behavior.
3: repair the bug. Again, we need to know what the correct behavior
is in order to change the program to achieve it.
If anyone would be so kind as to comb it for apparent flaws,
Flaws ... My pleasure! Actual errors might also be discovered if any
exists.
My <form> statement includes the following:... onSubmit="return
checkFields();"
That looks fine.
=================BEGIN SCRIPT==============

<SCRIPT language="JavaScript">
The "type" attribute is required in HTML 4, and is always suffient.
Use:
<script type="text/javascript">
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
Using HTML comments inside a Javascript instead of propert Javascript
comments: /* lala */
<!-- Begin
Attempting to "hide" the script from "old" browsers is not necessary.
Old browsers means Netscape 1 and contemporaries. They are no longer
in use, or if they are, the entire page will most likely fail blatantly.
function checkFields() {
missinginfo = "";
Local variables should be declared as such. This creates a global
variable, polluting the global namespace. Use:
var missinginfo = "";
if (document.form1.name.value == "") {
There are pages where this will fail, although it works in most
browsers on most (non XHTML) pages. To be safe, I recommend using:
if (document.forms['form1'].elements['name'].value == "") {
.... missinginfo += "\n - Name";
}

if (document.form1.website.value == "") {
.... and
if (document.forms['form1'].elements['website'].value == "") {
....
missinginfo += "\n - Website Name";
}
if (document.form1.links_URL.value == "") {
.... and ... you get the point.

It's probably prudent to make a shortcut to the form's elements.
Start the function with:
var form = document.forms['form1'].elements;
and then use, e.g.,
if (form['link_URL'].value == "") {
missinginfo += "\n - URL of your LINKS PAGE";
}

if ((document.form1.URL.value == "") ||
(document.form1.URL.value.indexOf("http://") == -1) ||
I would want the protocol to come first, so instead of "== -1", I would
do "!= 0"

if (missinginfo != "") {
missinginfo ="_____________________________\n" +
"You failed to correctly fill in your:\n" +
missinginfo + "\n_____________________________" +
"\nPlease re-enter and submit again!";
Since you cannot predict the font used by the alert dialog, using
a fixed number of underscores can give widely different visual
results on different pages.

else return true;


I recommend putting { and } around all if/else blocks, even when
not necessitated by the syntax. It eases reading profoundly.

else { return true; }

I see no errors in the script. If it fails to do as you expect, the
problem is either in your expectations or in the remainder of the
page. Is the name of the form really "form1"? As in:
<form id="form1" ...>
or
<form name="form1" ...>

Are the name of the mentioned form controls also correct?

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #3

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

Similar topics

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...
2
by: Czarina | last post by:
hi guys! here I am again, bugging you Here is where my page stands right now: http://www.gainesvillewebs.com/czar...h_results-2.htm The top 2 forms are working just fine, but the bottom one, with...
2
by: Mike Button | last post by:
Hello all, I am really really desperate on what I should do, and I am asking for help from anyone in this newsgroup, here's the situation: I am creating a form that is being run on a server...
2
by: qsweetbee | last post by:
I have a form(fAddUsers) in my database. It is continue form for data entry. Some fields are required fields. Some are optional fields. There is 1 particular filed(TokenExpirationDate)on the form...
4
by: usl2222 | last post by:
Hi folks, I appreciate any assistance in the following problem: I have a form with a bunch of dynamic controls on it. All the controls are dynamically generated on a server, including all...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
4
by: kktnguyen | last post by:
Hello, Please help me with this code..I have 4 forms which link to different htmll page. I try to write one validation file that can validate for the form whenever user click on that form.How do I...
2
by: John Smith | last post by:
Hello, I have a VB.NET application with a Windows form that have several textboxes fields where I have dates entered. I would like to do a date validation check after the the field is updated, so...
6
by: shapper | last post by:
Hello, I am creating a form that includes a few JQuery scripts and TinyMCE Editor: http://www.27lamps.com/Beta/Form/Form.html I am having a few problems with my CSS: 1. Restyling the Select
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
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
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
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
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...
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,...

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.