1

I have a requirement that if the yes/no check box column is checked then user dont need to fill the document name if it is not checked user should fill the document name so for that i using this presave action in the new form let me know what is wrong in this code i am not able to figure out.

function PreSaveAction() { 

var drpSection = $("select[title='Process']").val(); 
var drpDocumentName = $("select[title='Document Name']").val(); 
var drpDocumentNo = $("select[title='Document No']").val(); 
var drpRegional = $('input[type="checkbox"][name="Regional Document"]').val();

   if(drpSection == '0'){        
   alert("Please enter a Process"); 
   return false;  
    }
   else if(drpDocumentName == '0' && drpRegional == 'No'){        
   alert("Please enter a Document Name"); 
   return false;  
    }   
   else if(drpDocumentNo == '0'){ 
      alert("Please enter a Document No."); 
   return false;  
    }   
   else if(drpRegional == 'Yes' && drpDocumentName == '0'){
   return true;
    }
}

2 Answers 2

1

To check if a checkbox field is checked in the list form, please use the Jquery below:

$('input[type="checkbox"][title="testcheck"]').is(':checked')

enter image description here

enter image description here

0

Check what you are getting into,

var drpRegional = $('input[type="checkbox"][name="Regional Document"]').val();

because normally checkbox fields are boolean and they return True or false.

to find checked or not, you can use below example,

if($("#checkSurfaceEnvironment-1").prop('checked') == true){
//do something
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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