473,659 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

newbie: some errors reported by validator

Hello,
I am learning JavaScipt. I have written some functions and I verified my
code using http://www.jslint.com/ validator. I don't understand the
problems it reports. Could you help me please and invoke
http://www.jslint.com/ validator?
Thanks for help.
Here's the code:

var reEmail = /^[a-z0-9-.]{1,40}@[a-z0-9-.]{1,70}$/;
var reDate = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
var error_message = "";

// sprawdzać długości pól

function ValidateClient( )
{

var ok = true;
document.announ cement.client_e mail.className = "";
document.announ cement.client_m obile.className = "";
document.announ cement.client_p hone.className = "";
document.announ cement.client_t own.className = "";
document.announ cement.client_d irection.classN ame = "";
if (document.annou ncement.client_ email.value !== ""
&& !reEmail.test(d ocument.announc ement.client_em ail.value))
{
ok = false;
error_message += "Twój e-mail jest niepoprawny.\n" ;
document.announ cement.client_e mail.className = "error_fiel d";
}
if (document.annou ncement.client_ email.value === "" &&
document.announ cement.client_p hone.value === "" &&
document.announ cement.client_m obile.value === "")
{
ok = false;
error_message += "Proszę wprowadzić albo swój e-mail albo swój telefon
\n";
document.announ cement.client_e mail.className = "error_fiel d";
document.announ cement.client_m obile.className = "error_fiel d";
document.announ cement.client_p hone.className = "error_fiel d";
}
if (document.annou ncement.client_ town.value === "" &&
document.announ cement.client_d irection.value === "" &&
document.announ cement.client_p hone.value !== "")
{
ok = false;
error_message += "Proszę wprowadzić albo swoją miejscowość albo swój numer
kierunkowy.\n";
document.announ cement.client_t own.className = "error_fiel d";
document.announ cement.client_d irection.classN ame = "error_fiel d";
}
return ok;
}

function ClearClient()
{
document.announ cement.client_e mail.value = "";
document.announ cement.client_m obile.value = "";
document.announ cement.client_d irection.value = "";
document.announ cement.client_p hone.value = "";
document.announ cement.client_t own.value = "";
}

function ValidatePropert y()
{
var ok = true;
document.announ cement.floor_no .className = "";
document.announ cement.rooms.cl assName = "";
document.announ cement.year_bui lt.className = "";
if (document.annou ncement.floor_n o.value !== "" &&
isNaN(document. announcement.fl oor_no.value))
{
ok = false;
error_message += "Niepoprawn y numer piętra.\n";
document.announ cement.floor_no .className = "error_fiel d";
}
if (document.annou ncement.rooms.v alue !== "" &&
(isNaN(document .announcement.r ooms) || document.announ cement.rooms.va lue <
0))
{
ok = false;
error_message += "Niepoprawn a liczba pokoi.\n";
document.announ cement.rooms.cl assName = "error_fiel d";
}
var today = Date();
if (document.annou ncement.year_bu ilt.value !== "" &&
(isNaN(document .announcement.y ear_built.value ) ||
document.announ cement.year_bui lt.value today.getFullYe ar()))
{
ok = false;
error_message += "Niepoprawn y rok budowy.\n";
document.announ cement.year_bui lt.className = "error_fiel d";
}
// długość pola Uwagi
return ok;
}

function ClearProperty()
{
document.announ cement.floor_no .value = "";
document.announ cement.rooms.va lue = "";
document.announ cement.year_bui lt.value = "";
}

function isDate(strDate)
{
var matchArray = strDate.match(r eDate);
if (matchArray === null)
{
return false;
}
month = matchArray[1];
day = matchArray[3];
year = matchArray[5];
if (month < 1 || month 12)
{
return false;
}
if (day < 1 || day 31)
{
return false;
}
if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31)
{
return false;
}
if (month === 2)
{
var isLeap = (year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0));
if (day 29 || (day == 29 && !isLeap))
{
return false;
}
}
return true;
}

function ValidateAnnounc ement()
{
var ok = true;
document.announ cement.price.cl assName = "";
document.announ cement.valid_fr om.className = "";
document.announ cement.valid_to .className = "";
document.announ cement.offer_ty pe.className = "";
document.announ cement.price_fo r.className = "";
if (document.annou ncement.price.v alue !== "" &&
(isNaN(document .announcement.p rice.value) ||
document.announ cement.price.va lue < 0))
{
ok = false;
error_message += "Niepoprawn a cena dla oferty.\n";
document.announ cement.price.cl assName = "error_fiel d";
}
if (document.annou ncement.valid_f rom.value !== ""
&& !isDate(documen t.announcement. valid_from.valu e))
{
ok = false;
error_message += "Niepoprawn a data od kiedy ważne.\n";
document.announ cement.valid_fr om.className = "error_fiel d";
}
if (document.annou ncement.valid_t o.value !== ""
&& !isDate(documen t.announcement. valid_to.value) )
{
ok = false;
error_message += "Niepoprawn a data do kiedy ważne.\n";
document.announ cement.valid_to .className = "error_fiel d";
}
if (document.annou ncement.valid_f rom.value !== "" &&
document.announ cement.valid_to .value !== "" &&
document.announ cement.valid_fr om.value >
document.announ cement.valid_to .value)
{
ok = false;
error_message += "Data od kiedy ważne nie może być późniejsza niż data do
kiedy ważne.\n";
document.announ cement.valid_fr om.className = "error_fiel d";
document.announ cement.valid_to .className = "error_fiel d";
}
if (document.annou ncement.offer_t ype.value === "")
{
ok = false;
error_message += "Proszę wybrać rodzaj oferty.\n";
document.announ cement.offer_ty pe.className = "error_fiel d";
}
if (document.annou ncement.price.v alue !== "")
{
switch (document.annou ncement.offer_t ype.value)
{
case "W":
case "N":
if (document.annou ncement.price_f or.value != "M" &&
document.announ cement.price_fo r.value != "OM" &&
document.announ cement.price_fo r.value != "MOL" &&
document.announ cement.price_fo r.value != "MCZ" &&
document.announ cement.price_fo r.value != "MCZOL" &&
document.announ cement.price_fo r.value != "MZCZOL" &&
document.announ cement.price_fo r.value != "OMOL")
{
ok = false;
error_message += "Niepoprawn ie określono za co cena.\n";
document.announ cement.price_fo r.className = "error_fiel d";
}
break;
case "K":
case "S":
if (document.annou ncement.price_f or.value != "N")
{
ok = false;
error_message += "Niepoprawn ie określono za co cena, powinna
być 'nieruchomość '.\n";
document.announ cement.price_fo r.className = "error_fiel d";
}
break;
case "Z":
if (document.annou ncement.price_f or.value !== "")
{
ok = false;
error_message += "Niepoprawn ie określono za co cena, powinno być 'nie
dotyczy'.\n";
document.announ cement.price_fo r.className = "error_fiel d";
}
break;
}
}
if (document.annou ncement.caution )
{
if (document.annou ncement.offer_t ype.value != "W" &&
document.announ cement.offer_ty pe.value != "N")
{
ok = false;
error_message += "Kaucja ma sens tylko w przypadku najmu/wynajmu.\n";
document.announ cement.caution. className = "error_fiel d";
}
}
// długość pola Uwagi
return ok;
}

function ClearAnnounceme nt()
{
document.announ cement.price.va lue = "";
document.announ cement.valid_fr om.value = "";
document.announ cement.valid_to .value = "";
document.announ cement.offer_ty pe.value = "";
document.announ cement.price_fo r.value = "";
}

function AgencyRegionsSe lected()
{
for (var i = 0; i < document.announ cement.agency_r egion.length; i++)
{
if (document.annou ncement.agency_ region[i].checked === true)
{
return true;
}
}
return false;
}

function ValidateAgencie s()
{
var ok = false;
document.announ cement.agency_w holecountry.cla ssName = "";
if (!document.anno uncement.agency _wholecountry.c hecked === true
&& !AgencyRegionsS elected())
{
ok = true;
document.announ cement.agency_w holecountry.cla ssName = "error_fiel d";
error_message += "Proszę dokonać wyboru agencji.\n";
}
return ok;
}

function ValidateAndSubm it()
{
error_message = "";
if (ValidateClient () === true && ValidatePropert y() === true &&
ValidateAnnounc ement() === true && ValidateAgencie s() === true)
{
if (confirm('Czy jesteÅ› pewien?'))
{
document.announ cement.action = "announcement.p hp";
document.announ cement.submit() ;
}
}
else
{
alert(error_mes sage);
}
}

function ShowPicture(pic ture_no)
{
var w = window.open("pi cture.php?pictu re=" +
picture_no.toSt ring(), "Zdjęcie nr " +
picture_no, "location=1,sta tus=1,scrollbar s=1,width=200,h eight=200");
w.moveTo(100, 100);
}

function RemovePicture(p icture_no)
{
if (window.confirm ('Czy na pewno chcesz usunąć zdjęcie nr ' + picture_no
+ '?'))
{
document.announ cement.action = "remove_picture .php?picture=" +
picture_no.toSt ring();
document.announ cement.submit() ;
}
}

function ClearAgencyRegi ons()
{
for (var i = 0; i < 16; i++)
{
document.announ cement.agency_r egion[i].checked = false;
}
}

function ClearAgency()
{
ClearAgencyRegi ons();
document.anounc ement.agency_wh olecountry.valu e = "";
}

function PrintAnnounceme nt()
{
document.announ cement.action = "print.php" ; // pobrać dane z formularza a
nie bazy
document.announ cement.submit() ;
}

function CalculatePaymen t()
{
var agencies = 0;
if (document.annou ncement.agency_ wholecountry)
{
agencies = agencies_in_Pol and;
}
else
{
for (var i = 0; i < 16; i++)
{
if (document.annou ncement.agency_ region[i].checked === true)
{
agencies += agencies_in_reg ions[i];
}
}
}
var payment = 0;
if (agencies 0)
{
payment = fixed_cost + Math.floor(agen cies * 1.0 /
agencies_per_va riable_cost) * variable_cost;
}
document.announ cement.payment. value = payment.toFixed (2);
}
Jun 27 '08 #1
3 1385
In article <g3**********@n ews2.task.gda.p l>, r_********@pocz ta.onet.pl wrote:
>Hello,
I am learning JavaScipt. I have written some functions and I verified my
code using http://www.jslint.com/ validator. I don't understand the
problems it reports. Could you help me please and invoke
http://www.jslint.com/ validator?
Thanks for help.
Why don't *you* invoke it, show us the problems it reports, and explain why
you don't understand them?
Jun 27 '08 #2
Why don't *you* invoke it, show us the problems it reports, and explain
why you don't understand them?
OK, no problem. Here's list of errors:

---
Error:

Implied global: agencies_in_Pol and 301, agencies_in_reg ions 309,
agencies_per_va riable_cost 316, alert 256, confirm 248, day 94, document 11
43 53 81 122 211 220 233 250 271 280 287 292 299, fixed_cost 316, month 93,
variable_cost 316, window 263 269, year 95

Problem at line 234 character 73: Missing 'new' prefix when invoking a
constructor.

if (!document.anno uncement.agency _wholecountry.c hecked === true
&& !AgencyRe...

Problem at line 246 character 9: Missing 'new' prefix when invoking a
constructor.

if (ValidateClient () === true && ValidatePropert y() === true &&
ValidateAnno...

Problem at line 246 character 38: Missing 'new' prefix when invoking a
constructor.

if (ValidateClient () === true && ValidatePropert y() === true &&
ValidateAnno...

Problem at line 246 character 69: Missing 'new' prefix when invoking a
constructor.

if (ValidateClient () === true && ValidatePropert y() === true &&
ValidateAnno...

Problem at line 246 character 104: Missing 'new' prefix when invoking a
constructor.

if (ValidateClient () === true && ValidatePropert y() === true &&
ValidateAnno...

Problem at line 286 character 5: Missing 'new' prefix when invoking a
constructor.

ClearAgencyRegi ons();
---

I don't understand why ClearAgencyRegi ons() and ValidateClient( ) is treated
as invoking constructor. I have such functions defined, and I don't
understand why validator doesn't see a function call in the commands.
Please explain.
Thanks.
/RAM/

Jun 27 '08 #3
In comp.lang.javas cript message <g3**********@n ews2.task.gda.p l>, Wed,
18 Jun 2008 21:57:04, r_********@pocz ta.onet.pl posted:
>var reEmail = /^[a-z0-9-.]{1,40}@[a-z0-9-.]{1,70}$/;
^^^^^^^^^^^^^^^ ^
That will reject valid addresses, not only because it rejects upper-
case. See <URL:http://www.merlyn.demo n.co.uk/js-valid.htm>.
>var reDate = /^(\d{4})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
^^^^ ^^^^
The second separator should match the first : use a backreference, \2 .

>function isDate(strDate)
{
var matchArray = strDate.match(r eDate);
if (matchArray === null)
{
return false;
}
month = matchArray[1];
day = matchArray[3];
year = matchArray[5];
if (month < 1 || month 12)
{
return false;
}
if (day < 1 || day 31)
{
return false;
}
if ((month == 4 || month == 6 || month == 9 || month == 11) &&
day == 31)
{
return false;
}
if (month === 2)
{
var isLeap = (year % 4 === 0 && (year % 100 !== 0 ||
year % 400 === 0));
if (day 29 || (day == 29 && !isLeap))
{
return false;
}
}
return true;
}
That can be done very much more simply; see via
<URL:http://www.merlyn.demo n.co.uk/js-dates.htm>. A detail on your
method : there is no need to calculate isLeap unless the month is 2 AND
the day is 29.
>function ClearAnnounceme nt()
{
document.announ cement.price.va lue = "";
document.announ cement.valid_fr om.value = "";
document.announ cement.valid_to .value = "";
document.announ cement.offer_ty pe.value = "";
document.announ cement.price_fo r.value = "";
}
That would be nicer as

function ClearAnnounceme nt()
{ var da = document.announ cement
da.price.value = "";
da.valid_from.v alue = "";
da.valid_to.val ue = "";
da.offer_type.v alue = "";
da.price_for.va lue = "";
}
if (ValidateClient () === true
^^^^^^^^
There should be no need for === true or == true if
ValidateClient is properly written to return a Boolean.

The preferred right margin for News is about 72 characters; and code
posted should be executable as is. Therefore, indenting in units of two
spaces is better than indenting in tabs.

--
(c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05.
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html-Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demo n.co.uk/news-use.htm: about usage of News.
No Encoding. Quotes precede replies. Snip well. Write clearly. Mail no News.
Jun 27 '08 #4

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

Similar topics

24
2484
by: Massimo Soricetti | last post by:
Hello, I'm not a C newbie, but I'm teaching C programming (well... FIRST programming and then C) to other guys these days and it's driving me to some reflexions on the language. It's not uncommon to forget a } writing code, and at compiling time get an error 18956778 lines after the mistake, in an otherwise absolutely correct piece of code. Or, sometimes in my journeys I got errors reported in a file, checked and found it correct, and...
4
1899
by: Allthumbs | last post by:
Hi, Both laptops seem to have the same set up office 2002 and windows XP. But copyfromrecordset works fine on one PC and fails in another. It does not throw any exception. Help!! thanks,
0
1030
by: John Oliver | last post by:
I'm having a devil of a time with phpBT. It displays nothing but a blank screen. I'm trying to get some kind of indication of what's going on, but am having no luck whatsoever. I've tried: log_errors = On error_log = /var/log/php.log And:
13
2678
by: kolmogolov | last post by:
/* Hi, I have removed things irrelevant to reproducing the problem. What's wrong with my code? Thanks in advance for any hint! 1166425362 */ #include <stdio.h> #include <stdlib.h> #include <string.h>
6
4502
by: quanghoc | last post by:
Hi all, I used XMLSpy to validate my XML but it catched one error at a time. Is there anyway to make XMLSpy to catch all errors at once. If XMLSpy does not have this feature, what software out there can do this? I have a very large document with many related files and validating one by one is a hassle. I want to see all errors and fix it all before coming back to validate again. Thanks.
2
1352
by: shk253 | last post by:
Hi all - The following is the code for one of my functions in a program but the compiler is reporting errors. I've also tried declaring the variable temp within the function but the number of errors reported by the compiler increases. Here's the code just for the function with problems: char options(); { cout<<"\n\nOption 1: Fahrenheit to Celsius - Press C or 1.\n"; cout<<"Option 2: Celsius to Fahrenheit - Press F or...
88
2689
by: Bill Cunningham | last post by:
Would anyone be interested in giving this a quick look. The compiler gave me so many errors I don't know where to start. This is my first use of isalpha. #include <stdio.h> #include <stdlib.h> #define ex exit(EXIT_FAILURE) int main(int argc, char *argv) {
37
3654
by: Prisoner at War | last post by:
Actually, it doesn't have to be a blockquote...but I'm at my wits' end: I want to make bold several lines of text which have a pair of <br /tags between them...seems like the <b></bdo not "carry over" when there are <br /tags involved...??? I've tried using <p style="font-weight: bold;"></p>, I've tried <blockquote></blockquote>...I just can't figure how I'm supposed to get the <b></btags to work for all the lines! Surely there must be...
2
2261
dlite922
by: dlite922 | last post by:
Hello Hello! I'm trying to connect to a host that accepts UDP on a port I setup and tested from a command line too called udp_write. However a PHP fsocketopen() call doesn't work nor does it give an error. stripped down code + fake data: $fp = fsockopen("udp://999.999.999.999",9999,$errNo,$errMsg) or die("$errNo : $errMsg"); $test = fwrite($fp, "Logging Test");
0
8428
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
8339
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
8851
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
8751
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...
0
8629
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...
1
6181
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
4338
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2757
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
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.