Jump to content

Disable already selected option in the same dropdowns


Recommended Posts

Hi there,

In case if you have 2 dropdowns where all of the options or some of them are equal and you don't want the same option to be choosen in both dropdowns, that JavaScript may help you:

<script>
document.addEventListener('DataPageReady', function (event) {
const dropdown1 = document.querySelector("#InsertRecordDropDown1");
const dropdown2 = document.querySelector("#InsertRecordDropDown2");

dropdown2.onchange = function () {
  let options1 = dropdown1.options;
  for (let a1 = 0; a1 < options1.length; a1++) {
    if (options1[a1].value == dropdown2.selectedOptions[0].value) {
      options1[a1].disabled = true;
    }
  }
};
dropdown1.onchange = function () {
  let options2 = dropdown2.options;
  for (let a2 = 0; a2 < options2.length; a2++) {
    if (options2[a2].value == dropdown1.selectedOptions[0].value) {
      options2[a2].disabled = true;
    }
  }
};
 
});
</script>

Make sure that you changed IDs of your dropdowns in constantas.

Hope someone find it useful=)

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...