/    Sign up×
Community /Pin to ProfileBookmark

How to block a dropdown if another is active?

Hello, I’m creating my first web page, and I want to do something simple for a test with javascript.
I have tried to do it in various ways but I am not getting the result I want. Could someone take the time to put the structure together so I can review it and learn how to do it?

Objetive:
I have two dropdowns, I want that when I select Active in the first one, the second dropdown is automatically put in Active and blocked, so that the user cannot interact with it.

How could I do it using only javascript?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@daveyerwinJun 10.2021 — @PonyRosa#1632787

``<i>
</i>&lt;select&gt;
&lt;option value="Active"&gt;ACTIVE&lt;/option&gt;
&lt;option value="Sedated" selected&gt;SEDATED&lt;/option&gt;
&lt;/select&gt;
&lt;select name="choice" disabled&gt;
&lt;option value="first"&gt;First Value&lt;/option&gt;
&lt;option value="second" selected&gt;Second Value&lt;/option&gt;
&lt;option value="third"&gt;Third Value&lt;/option&gt;
&lt;/select&gt;
&lt;script&gt;
document.querySelector('select').onchange=function(){
if(this.selectedOptions[0].value === 'Active')
document.querySelectorAll('select')[1].disabled = false
else
document.querySelectorAll('select')[1].disabled = true;
}
&lt;/script&gt;<i>
</i>
``
Copy linkTweet thisAlerts:
@PonyRosaauthorJun 10.2021 — That was the thing i was looking for, I will work on this code, thank you!!!!
Copy linkTweet thisAlerts:
@PonyRosaauthorJun 10.2021 — @DaveyErwin#1632802 That was the thing i was looking for, I will work on this code, thank you!!!!
×

Success!

Help @PonyRosa spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...