https://i.sstatic.net/xfNCt.png
When working with Woocommerce, I am attempting to dynamically display a certain number of child age fields based on the data entered in the initial child field. By default, these child age boxes are hidden using CSS. How can I achieve this functionality using jQuery? Any insights or suggestions would be greatly appreciated.
1) Code snippet for the child field:
<div class="yith-wcbk-form-section yith-wcbk-form-section-person-types">
<label for="yith-wcbk-booking-persons-type-390">
Child</label>
<input id="yith-wcbk-booking-persons-type-390" name="person_types[390]" class="yith-wcbk-booking-person-types yith-wcbk-number-minifield" step="1" min="0" max="4" data-person-type-id="390" value="" type="number">
</div>
2) Code snippet for the first age field:
<div class="yith-wcbk-form-section yith-wcbk-form-section-person-types">
<label for="yith-wcbk-booking-persons-type-450">
1st age</label>
<input id="yith-wcbk-booking-persons-type-450" name="person_types[450]" class="yith-wcbk-booking-person-types yith-wcbk-number-minifield" step="1" min="0" max="12" data-person-type-id="450" value="" type="number">
</div>
3) Although I tried implementing the following JavaScript code, it did not work as expected:
jQuery('#yith-wcbk-booking-persons-type-390').change(function(){
if(jQuery(this).val() === '1') {
jQuery('#yith-wcbk-booking-persons-type-450').show();
}
// Additional conditions and show functions omitted for brevity
});
This JSFiddle example works perfectly, but encounters issues when incorporated into a Wordpress environment.