Solarpitch Posted January 30, 2007 Share Posted January 30, 2007 When a web page loads and you see "Error on page" bottom left, can that affect the way in which Javascript functions are preformed? I have a basic validation function that I am trying to implement from: http://developer.apple.com/internet/webcontent/validation.htmlThe code doesnt seem to work however. I tried pasting everything into the page and using the external validate.js file called via src = "" but still no joy.I seem to have a few errors on my page regarding the height attribute not been compatible with IE 5+ and so on. Could these css error be preventing the validation from working or is their something in the code that needs to be changed?I currently have the code as follows:[code]// Register.php - I have the main check function that is calling the sub functions in validate.js (src = "validate")function checkWholeForm(theForm) { var why = ""; why += checkEmail(theForm.email.value); why += checkPhone(theForm.phone.value); why += checkPassword(theForm.password.value); why += checkUsername(theForm.username.value); why += isEmpty(theForm.notempty.value); why += isDifferent(theForm.different.value); for (i=0, n=theForm.radios.length; i<n; i++) { if (theForm.radios[i].checked) { var checkvalue = theForm.radios[i].value; break; } } why += checkRadio(checkvalue); why += checkDropdown(theForm.choose.selectedIndex); if (why != "") { alert(why); return false; }return true;}// and I have the usual ... action = "Process_Registration" OnSubmit = "return checkWholeForm(theForm)"[/code] [code]// Validate.js - sub functions// emailfunction checkEmail (strng) {var error="";if (strng == "") { error = "You didn't enter an email address.\n";} var emailFilter=/^.+@.+\..{2,3}$/; if (!(emailFilter.test(strng))) { error = "Please enter a valid email address.\n"; } else {//test email for illegal characters var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ if (strng.match(illegalChars)) { error = "The email address contains illegal characters.\n"; } }return error; }// phone number - strip out delimiters and check for 10 digitsfunction checkPhone (strng) {var error = "";if (strng == "") { error = "You didn't enter a phone number.\n";}var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters if (isNaN(parseInt(stripped))) { error = "The phone number contains illegal characters."; } if (!(stripped.length == 10)) { error = "The phone number is the wrong length. Make sure you included an area code.\n"; } return error;}// password - between 6-8 chars, uppercase, lowercase, and numeralfunction checkPassword (strng) {var error = "";if (strng == "") { error = "You didn't enter a password.\n";} var illegalChars = /[\W_]/; // allow only letters and numbers if ((strng.length < 6) || (strng.length > 8)) { error = "The password is the wrong length.\n"; } else if (illegalChars.test(strng)) { error = "The password contains illegal characters.\n"; } else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) { error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n"; } return error; } // username - 4-10 chars, uc, lc, and underscore only.function checkUsername (strng) {var error = "";if (strng == "") { error = "You didn't enter a username.\n";} var illegalChars = /\W/; // allow letters, numbers, and underscores if ((strng.length < 4) || (strng.length > 10)) { error = "The username is the wrong length.\n"; } else if (illegalChars.test(strng)) { error = "The username contains illegal characters.\n"; } return error;} // non-empty textboxfunction isEmpty(strng) {var error = ""; if (strng.length == 0) { error = "The mandatory text area has not been filled in.\n" }return error; }// was textbox alteredfunction isDifferent(strng) {var error = ""; if (strng != "Can\'t touch this!") { error = "You altered the inviolate text area.\n"; }return error;}// exactly one radio button is chosenfunction checkRadio(checkvalue) {var error = ""; if (!(checkvalue)) { error = "Please check a radio button.\n"; }return error;}// valid selector from dropdown listfunction checkDropdown(choice) {var error = ""; if (choice == 0) { error = "You didn't choose an option from the drop-down list.\n"; } return error;} [/code]Anyway, when submit is clicked no validation occurs at all and the Process_Registration paged is executed. Quote Link to comment https://forums.phpfreaks.com/topic/36403-errors-on-page-question/ Share on other sites More sharing options...
fenway Posted January 31, 2007 Share Posted January 31, 2007 No, the CSS won't be a problem... how far into the function do you get? Quote Link to comment https://forums.phpfreaks.com/topic/36403-errors-on-page-question/#findComment-173784 Share on other sites More sharing options...
bibby Posted February 1, 2007 Share Posted February 1, 2007 Use FireBug for FireFox.Excellent JS debugger. Quote Link to comment https://forums.phpfreaks.com/topic/36403-errors-on-page-question/#findComment-174435 Share on other sites More sharing options...
fenway Posted February 1, 2007 Share Posted February 1, 2007 Just throw in some alert()s and you'll find it faster. Quote Link to comment https://forums.phpfreaks.com/topic/36403-errors-on-page-question/#findComment-174707 Share on other sites More sharing options...
Solarpitch Posted February 1, 2007 Author Share Posted February 1, 2007 Will do! I'll give it a go . . cant be anything major! Quote Link to comment https://forums.phpfreaks.com/topic/36403-errors-on-page-question/#findComment-175032 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.