|
 |
javascript_howto thread: RE: javascript_howto digest: October 17, 2002
Message #1 by "Pallone, Claudio [KMR-SPC]" <Claudio.Pallone@k...> on Fri, 18 Oct 2002 13:19:37 +0100
|
|
Hi Garrett and thanks for sharing this code with us.
But please, could you also post the HTML code so that a beginner like me
can understand what is going on :)
Cheers,
Claudio
Subject: color error checking :)
From: "Garrett Steed" <gmsteed@s...>
Date: Thu, 17 Oct 2002 17:22:33 -0700
X-Message-Number: 5
/* ok so here is my goal make one form check element that can be created
active or passive depending on what you pass in to the object (still
working
on some).
First off I want to say thanks it thau! for The Book of JavaScript this
example is close to his for as reason....
I also want to make it basic enough that someone with the most simple
JavaScript skills could use. So here is what you do
place this at the top of the page where you want to have the javascript
be
<script type=3D"text/javascript"
src=3D"../../../inc/errorCheck.js"></script>
change the
src=3D"location" to the location of this file. Then change the var
located
below :) have fun
garrett
ps thanks for the great book thau!
*/
var domLocation =3D document.form2; //my form was named form2 you must
change
that to the name of your form.
var numberElem =3D domLocation.elements.length; //This counts how many
form
elements there are
var numberInRow =3D 3; //This will be the number of elements in a row...
ya
that's what it says
var numberOfExclusions =3D 0; //This is a weird function if you want to
skip
the first few elements (not used much)
var numberOfRows =3D (numberElem - numberOfExclusions)/numberInRow;
//Ok, so
given the infromation to the above this line you can now now the
numberOfRows
function formChecker(){
for (i=3D0; i<numberElem; i++){
if(domLocation.elements[i].style.background =3D=3D "yellow"){
domLocation.elements[i].style.background =3D "white";
}
if(domLocation.elements[i].style.color =3D=3D "red"){
domLocation.elements[i].style.color =3D "#4682B4";
}
}
var error =3D "";
for(i=3D0; i<numberElem; i++){
if(domLocation.elements[i].value =3D=3D "")
{
domLocation.elements[i].style.background =3D "yellow"; //Oh show the
folks
were they went wrong
error +=3D "You cannot have empty cells";
}
if(domLocation.elements[i].value<0)
{
domLocation.elements[i].style.color =3D "red"; // Once again show them
what's
up
error +=3D "You must have a numbers larger then zero. \n";
}
if(isNaN(parseInt(domLocation.elements[i].value)))
{
domLocation.elements[i].style.color =3D "red"; // And if they were silly
enought to do something weird....
error +=3D "You must have a numbers only. \n";
}
}
if (errorString =3D=3D ""){
return true; //Ok this return; if you place this function name
formChecker()
into an if statement you will either get a true or false
}
else{
error =3D "We found the following error in your form: \n" + error;
alert(error);
return false;
}
}
BMRB International
http://www.bmrb.co.uk +44 (0)20 8566 5000
____________________________________________________________
This message (and any attachment) is intended only for the recipient and
may contain confidential and/or privileged material. If you have
received this in error, please contact the sender and delete this
message immediately. Disclosure, copying or other action taken in
respect of this email or in reliance on it is prohibited. BMRB
International Limited accepts no liability in relation to any personal
emails, or content of any email which does not directly relate to our
business.
|
|
 |