473,598 Members | 3,183 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 1836
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
8742
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
1518
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
2925
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
4025
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
10137
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
3023
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
1433
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
6732
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
2184
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
7904
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
8051
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,...
1
5850
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
5438
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
3898
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
3940
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2414
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1505
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1250
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.