You are viewing limited content. For full access, please sign in.

Question

Question

uncheck a box when another box is check within a group of selections

asked on March 15, 2016 Show version history

I am having some difficulty making boxes uncheck when another box is check within a group of selection:

 

 

$('#Field134').change(function(){
    var check1 = $('input[id^=Field134]')[1].checked;
    var check2 = $('input[id^=Field134]')[2].checked;
    var check3 = $('input[id^=Field134]')[3].checked;
    if( check1 == true ) 
	{$('#Field134-2').checked(false);}
	{$('#Field134-3').checked(false);}
  });

 This is what I currently have but it doesn't seems to be working, what am I missing?  Thanks.

1 0

Replies

replied on March 15, 2016

Hi Tommy,

The indexing starts at [0], not [1]. Also, you have an extra "}{" on line 6/7, so your if-statement only surrounds line 6, and line 7 will always be active.

Since you're using jQuery, you could save some headaches by sticking with jQuery objects and using the ".prop()" method. For example:

$('#Field134').on('change', function(){
  var check1 = $('input[id^=Field134-0]').prop('checked');
  if(check1 == true){
    $('input[id^=Field134-1]').prop('checked', false);
    $('input[id^=Field134-2]').prop('checked', false);
  }
});

Let me know if this works for you!

1 0
replied on March 17, 2016

Thanks for the reply alexander,

Unfortunately with the provided code above does not indicate any function after applied.

0 0
replied on April 27, 2016

So how do you determine Field134-1?

Here is my form in the designer

Here is my code, .certNO is working but the certDocs section is not.

 

0 0
replied on April 7, 2017

I know this is old but I was running with the same problem. The reasoning to use checkboxes instead of buttons was simple: we needed to have every checkbox as a single group because we had radio button choices that would come right under the checkbox line if that one was selected. It took me a while but this code, allows you to use either a single group or group several checkbox groups together to where at any time, only one check box is selected for all the groups linked.

$('input[id^=Field]').on('click', function(){
  var checkboxlist = ['Field23','Field21','Field26'];
  var clicked= $(this).attr('id');
  var clickedshort= clicked.substr(0,clicked.search("-"));
  $(checkboxlist).each(function(){
     if(this==clickedshort){
      resetbox(checkboxlist);
      document.getElementById(clicked).checked = true; 
      };     
  });     
});
function resetbox(o){
  $(o).each(function(){
  $('input[id^='+this+']').prop("checked", false);
  });
}

I know is not the prettiest code (I am not a programmer nor know java like many others) but it gets the job accomplished. To link fields, just make them part of the array variable "checkboxlist" (ie. I linked in this example Field 23,21 and 26). Hope it helps those that may need this in the future.

1 0
replied on March 15, 2016 Show version history

Hello Tommy,

If you only want one of the options in that set to be checked at a time, I think you want to use radio buttons instead of checkboxes. A set of radio buttons by their definition only allows one to be checked at a time, while as you've seen there is no such restriction for checkboxes. If you need them to look visually like checkboxes there is a StackOverflow discussion on the topic.

Hope this helps!

ADDENDUM: Using radio buttons has the added advantage of having only one variable assigned to it (e.g. "accounts_applied") which will take some single value mapped to each option (e.g., "all", "user", "below"). With checkboxes, functionally you would have to check each box individually (pun intended) to see whether or not it is checked.

0 0
replied on March 17, 2016

James,

I am using check box so that it could be transferred via PDF output more easily from workflow.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.