Attempting to do my first bit of Javascript if / else. Basically I would like to display DIVs according to the number selected from the Radio box field. If option 3 is selected, I would like div 1, 2 and 3 to be visible. I am clearly going wrong somewhere. Thoughts / help is very much appreciated.
<script type="text/javascript" >
$(document).ready(function() {
$("input[name$='supplier']").click(function() {
var test = $(this).val();
if (test=1)
{
$("div.hidesupplier").hide();
$("#suppliersourced1").show();
}
else if (test=2)
{
$("div.hidesupplier").hide();
$("#suppliersourced1").show();
$("#suppliersourced2").show();
}
else if (test==3)
{
$("#suppliersourced1").show();
$("#suppliersourced2").show();
$("#suppliersourced3").show();
}
});
});
</script>
Number of Suppliers:
<label><input name="supplier" type="radio" value="1">1.</label>
<label><input name="supplier" type="radio" value="2">2.</label>
<label><input name="supplier" type="radio" value="3">3.</label>
<div id="suppliersourced1" class="CF hidesupplier" style="display: none;">Supplier One</div>
<div id="suppliersourced2" class="CF hidesupplier" style="display: none;">Supplier Two</div>
<div id="suppliersourced3" class="CF hidesupplier" style="display: none;">Supplier Three</div>
switch/casewould be better thanif/then/elseif