SitePoint Sponsor |
|
User Tag List
Results 1 to 1 of 1
-
Mar 6, 2004, 21:22 #1
I need help with a custom form validation script
I'm not very good at javascript at all, I haven't even touched it in forever. I am trying to write this function to validate my form, return an error or submit it, but it gives me the following error:
Error: 'manditory_fields' is null or is not an object.
This happens when I click submit on my form (the submit button is calling this function via onClick).
Here is the code:
HTML Code:<script language="JavaScript" type="text/javascript"> <!-- function check_logon_form(name) { var manditory_fields = new Array("username","password","access_code"); var error_fields = new Array(); var i; var j; var k = 1; var err_str; var obj = document.forms[name]; for ( i = 0; i <= manditory_fields.length; i++ ) { var field = obj.manditory_fields[i].value; if ( field == '' ) { error_fields[i] = manditory_fields[i]; } } if ( error_fields.length > 0 ) { err_str = '<b>The following errors occurred:</b><br />'; for ( j = 0; j <= error_fields.length; j++ ) { err_str += '- ' + error_fields[j]; if ( k < error_fields.length ) { err_str += '<br />'; } k++; } document.error_msg.InnerHTML = err_str; } else { obj.submit(); } } //--> <script>
Bookmarks