Jump to content

Cascading dropdown JS


Recommended Posts

i have this code and want it to set radioButtonActive.checked  = 'checked'; only when page changes not when its initially created but i think because it relates to the value of a cascading dropdown its is set top active everytime apart from if is true. how could i achieve this ?

 

<script>
if (document.DataPageReadyHandler == undefined) {

     const DataPageReadyHandler = (e) => {
          if (e.detail.appKey != '[@cbAppKey]') { return }
    
         const dropdown = document.querySelector('select[id*="EditRecordMW_Watch_Work_Work_Progress"]');
         const radioButtonComplete = document.querySelector('input[id*="EditRecordMW_Watch_Work_Work_Status"][value="Complete"]');
         const radioButtonActive = document.querySelector('input[id*="EditRecordMW_Watch_Work_Work_Status"][value="Active"]');
     
         dropdown.addEventListener('change', (e) => {
            if (e.target.value == '2'|| e.target.value == '12' || e.target.value == '21' || e.target.value == '113' || e.target.value == '116') {
                radioButtonComplete.checked  = 'checked';

            } else {
                radioButtonActive.checked  = 'checked';
            }
         })
    }
    document.addEventListener('DataPageReady', DataPageReadyHandler)
    document.DataPageReadyHandler = 'Enabled'
}
</script>

Link to comment
Share on other sites

Hi @Buggy,

I'm quite confused about the intended workflow. So if a DataPage loads, the JS will not select a radio button option. It will only select a radio button option when a Cascading dropdown has a selected option. Is that right?

Link to comment
Share on other sites

yes so when page loads the dropdown is selected and radiobutton is selected from value set previosly in the database but the js is setting radiobutton to "active" regardless. i only want it to do that if the value of the dropdown is changed by the user.

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...
×
×
  • Create New...