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

Question

Question

Tick a checkbox when a field is equal to a value. (Javascript)

asked on March 17, 2021

Hi,

I need some help with a JavaScript code.

So what I am trying to do is that when a field is populated by a lookup and the value is equal to something then tick a checkbox, if the value is not equal to what I am looking for don't tick a checkbox.

 

0 0

Replies

replied on March 17, 2021
//Example
CheckABox('myCheckbox','choice_2');


//Selects a checkbox choice given a checkbox class name and the option to choose
function CheckABox(checkBoxClass,nameOfChoice){
  //For each value in the checkbox options
 $('.'+checkBoxClass+' input[type=checkbox]').each(function() {
  //If the value matches the input, then check the box 
   if($(this).val() == nameOfChoice)
     $(this).prop('checked',true);
     
 });
    
}

 

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

Sign in to reply to this post.