vendredi 9 octobre 2015

show required checkbox based on select

I am new to javascript/jquery and have problem to make the checkbox mandatory based on the value of dropdown list. I want the checkbox is hide and not mandatory if "Guest" is selected, and show the checkbox and make it mandatory if "A/C" is selected. Anyone can help?

<script type="text/javascript">
function ShowHideDiv2() {
    var Payment1 = document.getElementById("Payment1");
    var BCO = document.getElementById("BCO");
    BCO.style.display = Payment1.value == "A/C" ? "block" : "none";
}
</script>

<select name="Payment 1" id="Payment1" editable="true" onchange = "ShowHideDiv2()">
<option value="null" selected>Select... </option>
<option value="A/C">A/C</option>
<option value="Guest">Guest</option>
</select>

<div id="BCO" style="display: none">
<input name="BCO Approved" type="checkbox" value="Yes">
I will pay by A/C.
</div>




Aucun commentaire:

Enregistrer un commentaire