Im setting up part of a form to show certain info when selected from a dropdown menu to show a different div
ie table one
table two
The issue I have got is when I select option two, option one still show and I want that to hide. Ive tried a few ways to do it and none work.
so code below works but when you press option two, option one is still visible.
Hope you can help?
I know this is really simple but my mind has gone blank on this one.
Thanks
Tim
<form class="p-3">
<div class="form-group">
<div class="form-group">
<select class="form-control" id="oneoffevent">
<option value="oneoffevent">table one</option>
<option value="weekly">table two</option>
</select>
</div>
<div class="" id="oneoffeventDiv">
<label for="oneoffevent">one off event info....</label></div>
<div class="" id="weeklyeventDiv">
<label for="weeklyevent">weekly info....</label></div>
</form>
<script>
$("#oneoffevent").change(function() {
if ($(this).val() == "weekly") {
$('#weeklyeventDiv').show();
$('#weeklyevent').attr('required', '');
$('#weeklyevent').attr('data-error', 'This field is required.');
} else {
$('#weeklyeventDiv').hide();
}
});
$("#oneoffevent").trigger("change");
$("#oneoffevent").change(function() {
if ($(this).val() == "weekly") {
} else {
$('#weeklyeventGroupDiv').hide();
}
});
$("#oneoffevent").trigger("change");
</script>