I'm querying a database to check if an email exists / has already been used. if the email has been used I need to change a radio selector to another option
I have never used a toggle event based on a database query email validation so as of now I have the jquery setup returning alerts.
<!--/* shipment opt-in */-->
<div class="row--flex">
<div class="form-group" data-sly-test="${!properties.defaultRefill}">
<input type="radio" id="inServiceKit_shipmentOptInSupportingMaterials" name="shipmentOptIn" class="form-control" checked="checked" required>
<label class="form_label" for="inServiceKit_shipmentOptInSupportingMaterials">
Please send me the COPD In-Service Kit and additional Supporting materials
</label>
</div>
<div class="form-group" data-sly-test="${properties.defaultRefill}">
<input type="radio" id="inServiceKit_shipmentOptInRefillOnly" name="shipmentOptIn" class="form-control" checked="checked" required>
<label class="form_label" for="inServiceKit_shipmentOptInRefillOnly">
Please send me the COPD In-Service Refill Kit
</label>
</div>
</div>
<!--/* end shipment opt-in */-->
$('#inServiceKit_email').on('change', function() {
//ajax request
$.ajax({
url: 'endpoint',
data: {
'email': $('#inServiceKit_email').val()
},
dataType: 'json',
success: function(data) {
if (data == true) {
alert('email is in database')
} else {
alert('email is valid')
}
},
error: function(data) {
//error
}
});
});
the form now shows the "please send me the COPD In Service Kit and additional Supporting materials" label, so if users email is in database I want that to change to the other label and radio check " Please send me the COPD In-Service Refill Kit"