After finishing up my first quarter JavaScript on 12/12/03, I decided
to improve character checking on my project. In my project I only had
to do very basic validation. Therefore, I only had one function to
verify the name fields, age, email and gender.
My question is: if I create a function for each field like the code
below, what would be the best way to organize the functions and call
them? Would I need one main function and place all other function
inside that function with one call or have separate function and a
separate call for each function.
Remember, please keep you explanation simple the only JavaScript
training I have had is less than three months in an online class where
I might add the book did not mention things like lastindexOf(),
charAt() and some other things that I was told to try.
Sue
function validate(FirstN ame) {
var Characters =
"abcdefghijklmn opqrstuvwxyzABC DEFGHIGJLMNOPQR STUVWXYZ"
var ok = "yes";
var temp;
for (var i=0; i<FirstName.val ue.length; i++) {
temp = "" + FirstName.value .substring(i, i+1);
if (Characters.ind exOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Please Enter a valid FirstName!");
document.Regist er.FirstName.va lue="";
document.Regist er.FirstName.fo cus();
}
}
Comment