Jump to content

Check 'Select All' in the Multi-select list box when a radio button is selected


Recommended Posts

Hi @JanineB - you may try this code:

<script type="text/javascript">
document.addEventListener('DataPageReady', function (event) {
 
var radios = document.getElementsByName("EditRecordFIELDNAME_RADIOBUTTON");

  for(i = 0; i < radios.length; i++) {
        if(radios[i].addEventListener('change', function() {
            if (this.value == 5) {

              var box = document.querySelectorAll("input[id*='EditRecordFIELDNAME_LISTBOX']");

                for (var i=0; i < box.length ;i++){
                 box[i].checked=true;
                 document.querySelector("input[id*='selectAllCbx_FIELDNAME']").click();
                }
        }

            else {

               var box= document.querySelectorAll("input[id*='EditRecordFIELDNAME_LISTBOX']");

                 for (var i=0; i < box.length ;i++){
                  box[i].checked=false;
                  document.querySelector("input[id*='selectAllCbx_FIELDNAME']").click();
                 }

         }
             
}));
    
}

});

</script>

This is for Details Page or Update Form. If you are planning to use it in the Submission Form, it will be InsertRecordFIELDNAME. Kindly change the FIELDNAME as well to the correct name of your field.

This code means that it will first get all values from the radio button and when it is changed, it will check if the value is equal to 5.

If the radio = 5 THEN select the Listbox AND check all options.
If the radio is not equal to 5 THEN it will uncheck all options. 

Hope it helps!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...