Issue
Greeting guys,
I'm new to this coding and requires help.
I want to make dropdown list B disable on default.
For example, in dropdown list A has "Yes", "No". If user select "Yes". Then the dropdown list B will be available to select. But default, the dropdown list A is always selected = "No".
Dropdown list B (Disable on default)
<label for="new">New staff join Date: </label>
<form method="post" action="?">
<select name="ckb" id="ck1">
<option disabled selected="select">-----Select Cut-----</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
Really appreciates the help :D
Solution
You could use:
document.getElementById("elementId").disabled = true;
Just change the value to true/false to disable and enable the element.
And for your dropdown on Yes/No you need to add onChange eventListener to your select and in the callback function add the code to disable when selected option is Yes.
For the default selected option in the YesNo select, just add selected attribute to the option you want to be selected on default.
function onChangeYesNo(option) {
if(option.value == "Yes"){
document.getElementById("dropwdown1").disabled = false;
}else{
document.getElementById("dropwdown1").disabled = true;
}
}
<select id="yesNo" onchange="onChangeYesNo(this)">
<option value="Yes">Yes</option>
<option value="No" selected>No</option>
</select>
<select id="dropwdown1" disabled="true">
<option value="val1">val1</option>
<option value="val2">val2</option>
</select>
Answered By - Francis G
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.