i have form with checkbox and submit method by jquery like this :
$("form.adj_baru").submit(function (event) {
event.preventDefault();
if (confirm('Anda yakin akan submit ?')) {
var formData = new FormData($(this)[0]);
var cekbox = $("input[name=size]").val();
if (cekbox === "") {
alert("Pilih salah satu ukuran !");
return;
}
$.ajax({
url: 'adj/adj_crud.php', //type='add_adj'
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (data) {
console.log(data);
}
});
}
return false;
});
<body>
<script src="http://ift.tt/1oMJErh"></script>
<form class='adj_baru'>
<label>Checkbox : </label><br>
<input type='checkbox' name='size' value='m'>M<br>
<input type='checkbox' name='size' value='l'>L<br>
<input type='checkbox' name='size' value='xl'>XL<br>
<input type='submit' value='SUBMIT'>
</form>
</body>
the alert alert("Pilih salah satu ukuran !") not working when the checkbox empty. how to alert if the checkbox not checked either and checked no more than one
Aucun commentaire:
Enregistrer un commentaire