I am trying to add radio button into dialog box using sweet alert but I'm not able to do it. Following is the code:
swal({
title: "<small>Please select an reason to cancel this job !</small>",
type: "warning",
text:"<input type=\"radio\" name=\"reason\" value=\"male\">Reason 1<br><input type=\"radio\" name=\"reason\" value=\"female\">Reason 2<br><input type=\"radio\" name=\"reason\" value=\"female\">Other Reason",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: false,
closeOnCancel: false,
html: true
},
function(isConfirm){
if (isConfirm) {
swal("Result !","Job cancelled successfully.");
} else {
swal("Cancelled !", "Process aborted");
}
});
SweetAlert2 supports radio inputs out of the box: https://sweetalert2.github.io/#input-radio
Swal.fire({
title: 'Select color',
input: 'radio',
inputOptions: {
'#ff0000': 'Red',
'#00ff00': 'Green',
'#0000ff': 'Blue'
},
// validator is optional
inputValidator: function(result) {
if (!result) {
return 'You need to select something!';
}
}
}).then(function(result) {
if (result.isConfirmed) {
Swal.fire({
icon: 'success',
html: 'You selected: ' + result.value
});
}
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With