I need to write a javascript/jquery code that make the checkbox if unchecked do not put a validation of a textbox and if checked the text box is validated for null or empty in my SP 2010 list form.
I have written code for checking the checkbox, and it works but when I uncheck the checkbox which is already checked, I am not able to get the value or trigger the event.
I added this code within a content editor web part.

    $(document).ready(function() {

     var checked0 = $(this).is(":checked");
     if (checked0) 
    //      alert('orc bi epm is checkedd111');

     ORCBIEPMchecked =true;  
      ORCBIEPMchecked =false;

Try using,

  if (document.getElementById('xxx').checked) 
     // add your stuff here.
      // do the stuff here.

or just put your code out of $(document).ready(). Since the page might be not loading when you uncheck the checkbox. And hence it might be not hitting the condition and that event.

  • you said "just put your code out of $(document).ready(). " Can you pls tell, where will I put the code, then. Will the same change click event will work on PreSaveAction function call? – userAZLogicApps Oct 27 '15 at 7:00
  • Yeah it will work on PreSaveAction function but you need to use the different ID there. – Niranjan Kulkarni Oct 27 '15 at 7:05
  • 1
    On what basis are you validating, I mean is it on a button click or some other event. If it is on a button click event then call your function on that button click event. Or write the code there in that button click event. – Niranjan Kulkarni Oct 27 '15 at 7:06

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.