RE: JavaScript validation errors
Hi all, It appears a faulty JavaScript function was being plugged in elsewhere in the application. This was causing JavaScript rendering errors when the page loaded. I've removed the faulty script and the client side validation works perfectly. Thanks for all the suggestions Sean -Original Message- From: O'Shea, Sean Sent: Monday, August 14, 2006 10:32 AM To: user@struts.apache.org Subject: RE: JavaScript validation errors Hi Srinivas, I tried setting my login form like this: . ... Still no luck in getting the javascript function called though. I've checked the source of the generated page and it looks like the validateLoginForm function is getting generated: function validateLoginForm(form) { if (bCancel) return true; else var formValidationResult; formValidationResult = validateRequired(form); return (formValidationResult == 1); } function loginForm_required () { this.a0 = new Array("SSN", "SSN is required.", new Function ("varName", " return this[varName];")); this.a1 = new Array("password", "Password is required.", new Function ("varName", " return this[varName];")); } The generated validateRequired function looks like this: function validateRequired(form) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + formName.value + '_required()'); . I'm guessing the intent of the eval('new ' + formName.value + '_required()'); line is to call the loginForm_required function? I made a little change to the validateRequired.js in the org.apache.commons.validator.javascript to alert when the function is called: /*$RCSfile: validateRequired.js,v $ $Revision: 1.13 $ $Date: 2004/03/28 16:53:21 $ */ /** * Check to see if fields must contain a value. * Fields are not checked if they are disabled. * * @param form The form validation is taking place on. */ function validateRequired(form) { alert("Calling required ") . But this doesn't even get called. My browser says that there is an error on line 1081 on the page - looking at this line I see this: //End --> My browser says it expects a '}' - it appears that there is a missing closing brace somewhere in the code? Has anyone else come across this problem? Thanks Sean -----Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, August 14, 2006 5:39 AM To: Struts Users Mailing List Subject: RE: JavaScript validation errors Hi sean, i think if you put onsubmit="return validateLoginForm(this); it works fine with client(front-end validation)side and if you remove onsubmit from jsp then it works fine with server(backend validation)may be this helps you Thanks, Srinivas. "O'Shea, Sean" To 08/12/2006 12:11 cc AM Subject RE: JavaScript validation errors Please respond to "Struts Users Mailing List" <[EMAIL PROTECTED] he.org> Hi, I'm not writing the JavaScript code myself, so I cannot include a check like you suggested. The JavaScript is being automatically generated using the tag. The generated validateRequired method is taken directly from the commons-validator.jar: function validateRequired(form) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + formName.value + '_required()'); for (x in oRequired) { var field = form[oRequired[x][0]]; if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea' || field.type == 'file' || field.type == 'checkbox' || field.type == 'select-one' || field.type == 'password') && field.disabled == false) { var value = ''; // get field's value if (field.type == "select-one") { var si = field.selectedIndex; if (si >= 0) { value = field.options[si].value; } } else if (field.type == 'checkbox') { if (
RE: JavaScript validation errors
Try to put instead of ...just a trial.. Thanks, Srinivas. "O'Shea, Sean" To 08/14/2006 08:02 cc PM Subject RE: JavaScript validation errors Please respond to "Struts Users Mailing List" <[EMAIL PROTECTED] he.org> Hi Srinivas, I tried setting my login form like this: . ... Still no luck in getting the javascript function called though. I've checked the source of the generated page and it looks like the validateLoginForm function is getting generated: function validateLoginForm(form) { if (bCancel) return true; else var formValidationResult; formValidationResult = validateRequired(form); return (formValidationResult == 1); } function loginForm_required () { this.a0 = new Array("SSN", "SSN is required.", new Function ("varName", " return this[varName];")); this.a1 = new Array("password", "Password is required.", new Function ("varName", " return this[varName];")); } The generated validateRequired function looks like this: function validateRequired(form) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + formName.value + '_required()'); . I'm guessing the intent of the eval('new ' + formName.value + '_required()'); line is to call the loginForm_required function? I made a little change to the validateRequired.js in the org.apache.commons.validator.javascript to alert when the function is called: /*$RCSfile: validateRequired.js,v $ $Revision: 1.13 $ $Date: 2004/03/28 16:53:21 $ */ /** * Check to see if fields must contain a value. * Fields are not checked if they are disabled. * * @param form The form validation is taking place on. */ function validateRequired(form) { alert("Calling required ") . But this doesn't even get called. My browser says that there is an error on line 1081 on the page - looking at this line I see this: //End --> My browser says it expects a '}' - it appears that there is a missing closing brace somewhere in the code? Has anyone else come across this problem? Thanks Sean -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, August 14, 2006 5:39 AM To: Struts Users Mailing List Subject: RE: JavaScript validation errors Hi sean, i think if you put onsubmit="return validateLoginForm(this); it works fine with client(front-end validation)side and if you remove onsubmit from jsp then it works fine with server(backend validation)may be this helps you Thanks, Srinivas. "O'Shea, Sean" To 08/12/2006 12:11 cc AM Subject RE: JavaScript validation errors Please respond to "Struts Users Mailing List" <[EMAIL PROTECTED] he.org> Hi, I'm not writing the JavaScript code myself, so I cannot include a check like you suggested. The JavaScript is being automatically generated using the tag. The generated validateRequired method is taken directly from the commons-validator.jar: function validateRequired(form) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + formName.value + '_required()'); for (x in oRequired) { var field = form[oRequired[x][0]]; if ((field.type == 'hidden' || field.type == 'text' |
RE: JavaScript validation errors
Hi Srinivas, I tried setting my login form like this: . ... Still no luck in getting the javascript function called though. I've checked the source of the generated page and it looks like the validateLoginForm function is getting generated: function validateLoginForm(form) { if (bCancel) return true; else var formValidationResult; formValidationResult = validateRequired(form); return (formValidationResult == 1); } function loginForm_required () { this.a0 = new Array("SSN", "SSN is required.", new Function ("varName", " return this[varName];")); this.a1 = new Array("password", "Password is required.", new Function ("varName", " return this[varName];")); } The generated validateRequired function looks like this: function validateRequired(form) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + formName.value + '_required()'); . I'm guessing the intent of the eval('new ' + formName.value + '_required()'); line is to call the loginForm_required function? I made a little change to the validateRequired.js in the org.apache.commons.validator.javascript to alert when the function is called: /*$RCSfile: validateRequired.js,v $ $Revision: 1.13 $ $Date: 2004/03/28 16:53:21 $ */ /** * Check to see if fields must contain a value. * Fields are not checked if they are disabled. * * @param form The form validation is taking place on. */ function validateRequired(form) { alert("Calling required ") . But this doesn't even get called. My browser says that there is an error on line 1081 on the page - looking at this line I see this: //End --> My browser says it expects a '}' - it appears that there is a missing closing brace somewhere in the code? Has anyone else come across this problem? Thanks Sean -----Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Monday, August 14, 2006 5:39 AM To: Struts Users Mailing List Subject: RE: JavaScript validation errors Hi sean, i think if you put onsubmit="return validateLoginForm(this); it works fine with client(front-end validation)side and if you remove onsubmit from jsp then it works fine with server(backend validation)may be this helps you Thanks, Srinivas. "O'Shea, Sean" To 08/12/2006 12:11 cc AM Subject RE: JavaScript validation errors Please respond to "Struts Users Mailing List" <[EMAIL PROTECTED] he.org> Hi, I'm not writing the JavaScript code myself, so I cannot include a check like you suggested. The JavaScript is being automatically generated using the tag. The generated validateRequired method is taken directly from the commons-validator.jar: function validateRequired(form) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + formName.value + '_required()'); for (x in oRequired) { var field = form[oRequired[x][0]]; if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea' || field.type == 'file' || field.type == 'checkbox' || field.type == 'select-one' || field.type == 'password') && field.disabled == false) { var value = ''; // get field's value if (field.type == "select-one") { var si = field.selectedIndex; if (si >= 0) { value = field.options[si].value; } } else if (field.type == 'checkbox') { if (field.checked) { value = field.value; } } else { value = field.value; } if (trim(value).length == 0) { if (i == 0) { focusField = field; } fields[i++] = oRequired[x][1]; isValid = false; } } else if (field.type =
RE: JavaScript validation errors
Hi sean, i think if you put onsubmit="return validateLoginForm(this); it works fine with client(front-end validation)side and if you remove onsubmit from jsp then it works fine with server(backend validation)may be this helps you Thanks, Srinivas. "O'Shea, Sean" To 08/12/2006 12:11 cc AM Subject RE: JavaScript validation errors Please respond to "Struts Users Mailing List" <[EMAIL PROTECTED] he.org> Hi, I'm not writing the JavaScript code myself, so I cannot include a check like you suggested. The JavaScript is being automatically generated using the tag. The generated validateRequired method is taken directly from the commons-validator.jar: function validateRequired(form) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + formName.value + '_required()'); for (x in oRequired) { var field = form[oRequired[x][0]]; if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea' || field.type == 'file' || field.type == 'checkbox' || field.type == 'select-one' || field.type == 'password') && field.disabled == false) { var value = ''; // get field's value if (field.type == "select-one") { var si = field.selectedIndex; if (si >= 0) { value = field.options[si].value; } } else if (field.type == 'checkbox') { if (field.checked) { value = field.value; } } else { value = field.value; } if (trim(value).length == 0) { if (i == 0) { focusField = field; } fields[i++] = oRequired[x][1]; isValid = false; } } else if (field.type == "select-multiple") { var numOptions = field.options.length; lastSelected=-1; for(loop=numOptions-1;loop>=0;loop--) { if(field.options[loop].selected) { lastSelected = loop; value = field.options[loop].value; break; } } if(lastSelected < 0 || trim(value).length == 0) { if(i == 0) { focusField = field; } fields[i++] = oRequired[x][1]; isValid=false; } } else if ((field.length > 0) && (field[0].type == 'radio' || field[0].type == 'checkbox')) { isChecked=-1; for (loop=0;loop < field.length;loop++) { if (field[loop].checked) { isChecked=loop; break; // only one needs to be checked } } if (isChecked < 0) { if (i == 0) { focusField = field[0]; } fields[i++] = oRequired[x][1]; isValid=false; } } } if (fields.length > 0) { focusField.focus(); alert(fields.join('\n')); } return isValid; } // Trim whitespace from left and right sides of s. function trim(s) { return s.replace( /^\s*/, "" ).replac
RE: JavaScript validation errors
Hi, I'm not writing the JavaScript code myself, so I cannot include a check like you suggested. The JavaScript is being automatically generated using the tag. The generated validateRequired method is taken directly from the commons-validator.jar: function validateRequired(form) { var isValid = true; var focusField = null; var i = 0; var fields = new Array(); var formName = form.getAttributeNode("name"); oRequired = eval('new ' + formName.value + '_required()'); for (x in oRequired) { var field = form[oRequired[x][0]]; if ((field.type == 'hidden' || field.type == 'text' || field.type == 'textarea' || field.type == 'file' || field.type == 'checkbox' || field.type == 'select-one' || field.type == 'password') && field.disabled == false) { var value = ''; // get field's value if (field.type == "select-one") { var si = field.selectedIndex; if (si >= 0) { value = field.options[si].value; } } else if (field.type == 'checkbox') { if (field.checked) { value = field.value; } } else { value = field.value; } if (trim(value).length == 0) { if (i == 0) { focusField = field; } fields[i++] = oRequired[x][1]; isValid = false; } } else if (field.type == "select-multiple") { var numOptions = field.options.length; lastSelected=-1; for(loop=numOptions-1;loop>=0;loop--) { if(field.options[loop].selected) { lastSelected = loop; value = field.options[loop].value; break; } } if(lastSelected < 0 || trim(value).length == 0) { if(i == 0) { focusField = field; } fields[i++] = oRequired[x][1]; isValid=false; } } else if ((field.length > 0) && (field[0].type == 'radio' || field[0].type == 'checkbox')) { isChecked=-1; for (loop=0;loop < field.length;loop++) { if (field[loop].checked) { isChecked=loop; break; // only one needs to be checked } } if (isChecked < 0) { if (i == 0) { focusField = field[0]; } fields[i++] = oRequired[x][1]; isValid=false; } } } if (fields.length > 0) { focusField.focus(); alert(fields.join('\n')); } return isValid; } // Trim whitespace from left and right sides of s. function trim(s) { return s.replace( /^\s*/, "" ).replace( /\s*$/, "" ); } Sean -Original Message- From: Monkeyden [mailto:[EMAIL PROTECTED] Sent: Friday, August 11, 2006 1:57 PM To: Struts Users Mailing List Subject: Re: JavaScript validation errors Are you returning false when there is an error in the validation? if(userName.trim().length() == 0){ alert("Pathetic, technologically inept users must enter a user name."); return false; } On 8/11/06, O'Shea, Sean wrote: > > Hi Adam, > > I changed my login form to look like this: > > > > > >: > > > key="login.correctssn"/> > > > > >: > > > key="login.correctpw"/> > > > > >"/> > > > > > > > > > But still no luck. My server side validation still works fine, but the > client side validation does not seem to execute. > Even when I look at the source for my JSP I can see the call to the > JavaScript function: > > onsubmit="return validateLoginForm(this);"> > > Its as if the variables are not getting loaded into the JavaScript > function, or the function is not getting called at all. > > Anyone have any ideas on this? &g
Re: JavaScript validation errors
Are you returning false when there is an error in the validation? if(userName.trim().length() == 0){ alert("Pathetic, technologically inept users must enter a user name."); return false; } On 8/11/06, O'Shea, Sean wrote: Hi Adam, I changed my login form to look like this: : : "/> But still no luck. My server side validation still works fine, but the client side validation does not seem to execute. Even when I look at the source for my JSP I can see the call to the JavaScript function: Its as if the variables are not getting loaded into the JavaScript function, or the function is not getting called at all. Anyone have any ideas on this? Thanks again Sean -Original Message- From: Adam Gordon [mailto:[EMAIL PROTECTED] Sent: Friday, August 11, 2006 11:56 AM To: Struts Users Mailing List Subject: Re: JavaScript validation errors Sean- You need to add an "onsubmit" attribute to your html:form" element that calls the validation function. Specifically, IIRC, it needs to say: onsubmit="return validateForm(this); happy coding, -adam O'Shea, Sean wrote: > Hi all, > > I'm using struts 1.2.7 with commons-validator-1.1.4 and I'm running into > a few generated JavaScript errors. Here's what my JSP looks like: > > > > > > > : > > >key="login.correctssn"/> > > > > > : > > >key="login.correctpw"/> > > > > > "/> > > > > > > > > > Here's what my action mapping looks like: > >type="LoginAction" > scope="request" validate="true" > input="login"> > . > > > This is what my form bean looks like: > >type="org.apache.struts.validator.DynaValidatorForm"> >type="java.lang.String" /> >type="java.lang.String" /> > > > My form validations look like this: > > > > > > > > > > > When I try to submit my loginForm. my server die validations work fine, > but the JavaScript does not get executed. From looking at the generated > source I see this: > >
RE: JavaScript validation errors
Hi Adam, I changed my login form to look like this: : : "/> But still no luck. My server side validation still works fine, but the client side validation does not seem to execute. Even when I look at the source for my JSP I can see the call to the JavaScript function: Its as if the variables are not getting loaded into the JavaScript function, or the function is not getting called at all. Anyone have any ideas on this? Thanks again Sean -Original Message- From: Adam Gordon [mailto:[EMAIL PROTECTED] Sent: Friday, August 11, 2006 11:56 AM To: Struts Users Mailing List Subject: Re: JavaScript validation errors Sean- You need to add an "onsubmit" attribute to your html:form" element that calls the validation function. Specifically, IIRC, it needs to say: onsubmit="return validateForm(this); happy coding, -adam O'Shea, Sean wrote: > Hi all, > > I'm using struts 1.2.7 with commons-validator-1.1.4 and I'm running into > a few generated JavaScript errors. Here's what my JSP looks like: > > > > > > > : > > >key="login.correctssn"/> > > > > > : > > >key="login.correctpw"/> > > > > > "/> > > > > > > > > > Here's what my action mapping looks like: > >type="LoginAction" > scope="request" validate="true" > input="login"> > . > > > This is what my form bean looks like: > >type="org.apache.struts.validator.DynaValidatorForm"> >type="java.lang.String" /> >type="java.lang.String" /> > > > My form validations look like this: > > > > > > > > > > > When I try to submit my loginForm. my server die validations work fine, > but the JavaScript does not get executed. From looking at the generated > source I see this: > >
Re: JavaScript validation errors
Sean- You need to add an "onsubmit" attribute to your html:form" element that calls the validation function. Specifically, IIRC, it needs to say: onsubmit="return validateForm(this); happy coding, -adam O'Shea, Sean wrote: Hi all, I'm using struts 1.2.7 with commons-validator-1.1.4 and I'm running into a few generated JavaScript errors. Here's what my JSP looks like: : : "/> Here's what my action mapping looks like: . This is what my form bean looks like: My form validations look like this: When I try to submit my loginForm. my server die validations work fine, but the JavaScript does not get executed. From looking at the generated source I see this: