0

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() {

        $("#ctl00_m_g_97fe2364_4242_487c_9dbc_8d1547697f5e_
   ctl00_ctl05_ctl17_ctl00_ctl00_ctl04_ctl00_ctl00").
     change(function() 
      {
     var checked0 = $(this).is(":checked");
     if (checked0) 
     {
    //      alert('orc bi epm is checkedd111');

     $("input[title='ORCBIEPM']").focus(); 
     $("input[Title='ORCBIEPM']").css("background-color","#FE2E2E"); 
     ORCBIEPMchecked =true;  
    }
   else
    {
      ORCBIEPMchecked =false;
    }
 });

1 Answer 1

1

Try using,

  if (document.getElementById('xxx').checked) 
  {
     // add your stuff here.
  } 
  else 
  {
      // 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.

3
  • 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?
    – samolpp2
    Commented Oct 27, 2015 at 7:00
  • Yeah it will work on PreSaveAction function but you need to use the different ID there. Commented Oct 27, 2015 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. Commented Oct 27, 2015 at 7:06

Your Answer

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

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