// js form checks by Adam @ QuizHeaven.com ... 9/2006 // If you steal this .. at least leave the comment. For posterity, that is. function validate_form(TheForm) { for ( x = 0; x <= TheForm.length; x++ ) { if (TheForm.elements[x].name == "opt_question") continue; // skip the optional question. blank = ignore. if (TheForm.elements[x].name.substr(0,6) == "image_") { if ( TheForm.elements[x].value.length >= 1 ) { var val = TheForm.elements[x].value; var str = val.toLowerCase(); if ( (str.substr(val.length - 5, 5) != ".jpeg") && (str.substr(val.length - 4, 4) != ".jpg") && (str.substr(val.length - 4, 4) != ".gif") && (str.substr(val.length - 4, 4) != ".png") ) { alert("Must be JPEG/JPG, GIF or PNG format." ); TheForm.elements[x].focus(); return false; } } else { continue; // skip the blank image url spots } } if (TheForm.elements[x].value.length == 0) { alert("You missed a spot!"); TheForm.elements[x].focus(); return false; } } return true; } // end validate_form func function fix_num(object) { if ( isNaN(object.value) ) { alert("Value must be a number!"); object.focus(); object.select(); return false; } return true; } function confirm_flag(TheForm) { var result; result = window.confirm("Are you SURE you want to flag this quiz?"); if ( result == true ) document.flagquizform.submit(); return result; } function ismaxlength(obj){ // don't remember where this came from. thanks, intarweb! var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : "" if (obj.getAttribute && obj.value.length>mlength) obj.value=obj.value.substring(0,mlength) } function validate_emailform(TheForm) { for ( x = 0; x <= TheForm.length; x++ ) { if ((TheForm.elements[x].name.substr(0,15) == "email_recipient") || (TheForm.elements[x].name.substr(0,12) == "email_sender") ) { var goodEmail = false if ( TheForm.elements[x].value.length == 0 ) continue if ( TheForm.elements[x].value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi) ) { goodEmail = true } if ( goodEmail == false ) { alert("Invalid Email Address."); TheForm.elements[x].focus(); TheForm.elements[x].select(); return false; } } } return true } function validate_email(TheForm) { var goodEmail = false; if ( TheForm.emailaddress.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi) ) { goodEmail = true } if ( goodEmail == false ) { alert("Invalid Email Address"); TheForm.emailaddress.focus(); TheForm.emailaddress.select(); return false; } return goodEmail; } function ConfirmDelQuiz() { var confirmation = confirm("Are you SURE you want to delete the selected quizzes?"); if ( confirmation ) return true; return false; }