Sure I have to attend a meeting all day today so I will try to get to it
this weekend :)
----- Original Message -----
From: "Claudio Pallone" <pallone@l...>
To: "JavaScript HowTo" <javascript_howto@p...>
Sent: Friday, October 18, 2002 1:33 PM
Subject: [javascript_howto] Re: color error checking :)
> 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
>
>
> > /* 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="text/javascript" src="../../../inc/errorCheck.js"></script>
> change the
> src="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 = document.form2; //my form was named form2 you must
change
> that to the name of your form.
> var numberElem = domLocation.elements.length; //This counts how many form
> elements there are
> var numberInRow = 3; //This will be the number of elements in a row... ya
> that's what it says
> var numberOfExclusions = 0; //This is a weird function if you want to skip
> the first few elements (not used much)
> var numberOfRows = (numberElem - numberOfExclusions)/numberInRow; //Ok, so
> given the infromation to the above this line you can now now the
> numberOfRows
>
> function formChecker(){
> for (i=0; i<numberElem; i++){
> if(domLocation.elements[i].style.background == "yellow"){
> domLocation.elements[i].style.background = "white";
> }
> if(domLocation.elements[i].style.color == "red"){
> domLocation.elements[i].style.color = "#4682B4";
> }
> }
>
> var error = "";
> for(i=0; i<numberElem; i++){
> if(domLocation.elements[i].value == "")
> {
> domLocation.elements[i].style.background = "yellow"; //Oh show the folks
> were they went wrong
> error += "You cannot have empty cells";
> }
> if(domLocation.elements[i].value<0)
> {
> domLocation.elements[i].style.color = "red"; // Once again show them
what's
> up
> error += "You must have a numbers larger then zero. \n";
> }
> if(isNaN(parseInt(domLocation.elements[i].value)))
> {
> domLocation.elements[i].style.color = "red"; // And if they were silly
> enought to do something weird....
> error += "You must have a numbers only. \n";
> }
> }
> if (errorString == ""){
> 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 = "We found the following error in your form: \n" + error;
> alert(error);
> return false;
> }
> }
>
>
>
>
>
> ---
>
> Improve your web design skills with these new books from Glasshaus.
>
> Usable Web Menus
> http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> r-20
> Constructing Accessible Web Sites
> http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> r-20
> Practical JavaScript for the Usable Web
> http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> r-20
>