I want to attain that a textbox will be changed to required="true" if a certain radio value is selected as Cash
this is my html form:
<label class="radio"> <input type="radio" name="payment" value="Cash" id="cashpayment" checked><span><img width="30" src="images/icons8-cash-in-hand-48.png"/></span></label>
<label class="radio"> <input type="radio" name="payment" value="SD" id="sdpayment"><span><img width="30" src="images/icons8-budget-48.png"/></span></label>
<label class="radio"> <input type="radio" name="payment" value="Budget" id="budgetpayment"><span><img width="30" src="images/icons8-office-48.png"/></span></label>
here is my jQuery code (jQuery v3.3.1)
$(document).ready(function(){
$("input[name='type']:radio").change(function(){
if($(this).val() == 'Cash')
{
$('#cashtender').attr('required');
}
else if($(this).val() == 'SD')
{
$('#cashtender').removeAttr('required');
}
else if($(this).val() == 'Budget')
{
$('#cashtender').removeAttr('required');
}
});
});
it's not working. please help