473,782 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="retur n
checkFields();"
=============== ==BEGIN SCRIPT========= =====

<SCRIPT language="JavaS cript">

<!-- 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.valu e == "") {
missinginfo += "\n - URL of your LINKS PAGE";
}

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

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

if(document.for m1.Description. value == "") {
missinginfo += "\n - Description of your Site";
}
if ((document.form 1.email.value == "") ||
(document.form1 .email.value.in dexOf('@') == -1) ||
(document.form1 .email.value.in dexOf('.') == -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(missingin fo);
return false;
}
else return true;
}
// End -->
</script>
=============== =======END SCRIPT========= ==========
Jul 23 '05 #1
2 1848
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="retur n
checkFields();"


Jul 23 '05 #2
"Axel Foley" <de*******@sync hkat.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="retur n
checkFields();"
That looks fine.
=============== ==BEGIN SCRIPT========= =====

<SCRIPT language="JavaS cript">
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.valu e == "") {
.... 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.form 1.URL.value == "") ||
(document.form1 .URL.value.inde xOf("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/rasterTriangleD OM.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
8756
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...
2
1523
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 the check boxes, it not working I am by NO MEANS, a Javascript expert, so please be patient! Here is what it needs to do: It need to check that at least 1 checkbox is selected, and if not, display error message.
2
2937
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 where there is no scripts allowed running (the software is from Opentext called Livelink)- therefore I need javascript to do the tasks listed below: 1. validate the form - this has been completed 2. pop up another window that will go ahead and...
2
4036
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 which is depended on the other field(TokenID)whether it is blank or not. If the "TokenID" field is blank, the "TokenExpirationDate" field can be blank also. But if the "TokenID" field is not blank or null, the "TokenExpirationDate" field must be...
4
10147
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 the validators. The user enters the data, presses OK. My OK button is dynamically generated as well, with some code-behind logic in
18
3043
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
1436
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 call Validate.js for each form? Please give me some hints. Thanks Validate.js ///////////////////////////////////////////////////////////////////////////////////////////////////////////// //test version //read the comment i put ...
2
6742
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 I' using the leave event. Right now I am creating a 'leave' sub for each of the fields. However, I'd like to simplify that and just call the name of a function and plug the field name as a variable and be done. In other words, I would like...
6
2195
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
9639
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
9479
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,...
0
10311
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10080
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
9942
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5509
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
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.