I have the following HTML form with 5 fields, in which one is a drop down list with two option (ward and room) and 4 other input text fields. I am trying to achieve that if I select ward from list, then room no and room name should be disabled. And if select Room from list then ward no and wardname should be disabled. Can I have a few bits of advice on how to achieve this?
$("select").change(function() {
if ($(this).val() == ward) {
$(".abc").attr("disabled", "disabled");
$(".abc1").attr("disabled", "disabled");
} else {
$(".roomno").attr("disabled", "disabled");
$(".roomname").attr("disabled", "disabled");
}
}).trigger("change");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<body>
<form method="post" action="">
<label>Sub Department :</label>
<select id="type">
<option value="ward">Ward</option>
<option value="room">Room</option>
</select>
<label> Ward No<input type = "text" name "abc" id = "abc">
<label> Ward Name <input type = "text" name "abc1" id = "abc1">
<label> Room No<input type = "text" name "roomno" id = "roomno">
<label> Room Name <input type = "text" name "roomname" id = "roomnam">
</form>
</body>
</html>
2
Answers
When you disable one set of inputs you have to enable the other set.
Other problems:
ward
in quotes to make it a string.#
to select by ID..
is for classes.<option>
in your<select>
</label>
=
after all thename
.