1

I need to iterate through the all the check boxes within my SPFieldMultiChoice and check whether at least any one of the checkboxes are checked and if not checked, I need to return false.
I have this field created in my newform.aspx in my presaveaction call. I tried with the below code , but it didn't work:

  if ($('input:checkbox:checked').length == 0) 
  { 
    alert('Enter at least one checkbox.');
  } 
 else
  {
  } 

Also below code also doesn't work.

   var count = $('#checkboxes input:checked').length;

I was trying to get the ID of the SPFieldMultiChoice field but,in the F12 Dev Console, am unable to see an ID for this control specifically.It's splitted into all the checkbox IDs, instead

1

I would do it like this:

if ($("input[type='checkbox']:checked").length == 0) 
  { 
    alert('Enter at least one checkbox.');
  } 
 else
  {
  }
  • Assume this is working and in my presaveaction call I am getting the alert, so the functionality is achieved.As a result, the end user checked one checkbox,so as per the logic,the length must be 1.But for me, its showing 0 again! Where am i doing wrong? – userAZLogicApps Oct 29 '15 at 15:17
  • I mean, I dont have a mechanism like, event handler, which tells to the js saying that I have checked one checkbox and again I am clicking the save button-presaveaction- call. – userAZLogicApps Oct 29 '15 at 15:23
  • Will this code fire again, after checking one check box and click on Save button, within my newform.aspx ? – userAZLogicApps Oct 29 '15 at 15:24
  • It should refire upon clicking save again if it is inside your presave function yes – Eric Alexander Oct 29 '15 at 15:29
  • Exactly,That's the problem,its not refiring! , and I have written the code its inside the presaveaction call only. – userAZLogicApps Oct 29 '15 at 15:34

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.