0

I am doing the JavaScript validation of SP 2010 list mynewcustomform.aspx page using the code written in content editor web part.

Fields are: textbox1, textbox2, textbox3.

var valoftxt1 = SPUtility.GetSPField('field1name').GetValue();
alert(valoftxt1 + ' == is the value ');
if(valoftxt1 == null ) { return false; }

  if(valofestimatedsize == null || valofestimatedsize.trim() 
     =="") 
{
 alert('Estimated size field is mandatory');
 return false;   
}   //till here the code is working fine

///////not working code from below onwards /////

   var valDurationinMonthsNew =      
          SPUtility.GetSPFieldByInternalName
       ('Duration_x0020__x0028_in_x0020_M').GetValue();
  alert(valDurationinMonthsNew + ' ==is the new  duration in months field 
  internal name');
  if(valDurationinMonthsNew == null || valDurationinMonthsNew.trim() 
    =="") 
    {
     alert('inside duration in months validation if condition');
     alert('Duration in months is mandatory field!');
       return false;   
    }

But I am not able to proceed with further validation of other fields.

I would like to know how to proceed with the other form fields' validation? Shouldn't I return return false statement on the first statement itself?

1

Try following code

var valoftxt1 = SPUtility.GetSPField('field1name').GetValue();
var valoftxt2 = SPUtility.GetSPField('field2name').GetValue();
var valoftxt3 = SPUtility.GetSPField('field3name').GetValue();

if (!valoftxt1 || !valoftxt2 || !valoftxt3) {
    return false;
}
  • my textbox2 is number field which has to be evaluated for numbers greater than zero.Its a Price field, so I have done validation for that also using parseFloat() but it did not work.Due to some reason after valoftxt1 validation is completed, unfortunately js is not validating the remaining line of code.little bit strange. – SaMolPP Oct 14 '15 at 13:50
  • Write me the whole validation logic – Atish Dipongkor - MVP Oct 14 '15 at 16:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.