I have a checkbox which functions as a toggle and when clicked submits a form with the check/unchecked status being used to enable/disable the service.
However, I now have an API which selects preferences based on location and I want to:
-
Click submit if the checkbox is unchecked
-
Click apply if the checkbox is checked
Currently I have $(“#checkbox”).click(); if the user calls the API and I’m not sure how to implement this where $(“#apply”).click(); would be used if the checkbox was checked already to avoid turning the service off. I've tried $('#checkbox').attr but not having problems with it.
$(‘#apicall’).off('click').on('click', function() {
$.ajax({
type : 'GET',
dataType : 'json',
url : "https:// [PRIVATE API REDACTED]“,
success : function(result){
console.log(result);
result=result.successData.server;
best_ovpn=best_ovpn.trim();
$(“#dropdown”).val(apical);
show_openvpn_status();
if($('#checkbox').attr('checked')) {
$("#checkbox").click();
} else {
$("#apply").click();
}
});
});
Aucun commentaire:
Enregistrer un commentaire