I'm looking for help with using jQuery to toggle between two radio buttons and display different divs based on the selection.
jQuery(document).ready(function($) {
if ($('#user_personal').is(':checked')) {
$('.user_company').addClass('hidden');
$('.user_personal').removeClass('hidden');
} else if ($('#user_company').is(':checked')) {
$('.user_personal').addClass('hidden');
$('.user_company').removeClass('hidden');
}
});
.hidden {
display: none
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="user-type-item">
<input name="user" id="user_personal" type="radio">
</div>
<div class="user-type-item">
<input name="user" id="user_company" type="radio">
</div>
<div class="user_personal">
<select name="" id="" class="form-control">
<option value="0"></option>
</select>
</div>
<div class="user_company">
<input type="text" class="form-control">
</div>
This jQuery code will show/hide div elements based on which radio button is selected. When "#user_personal" is checked, "div.user_company" will have the "hidden" class added and "div.user_personal" will have it removed. Similarly, when "#user_company" is checked, "div.user_personal" will have the "hidden" class added and "div.user_company" will have it removed.
Thank you in advance for any assistance!