How can I change the text of the buttons that appear in the function confirm()
of JavaScript?
The default texts are "Accept" and "Cancel". I would like to put "Yes" and "No". Any ideas?
How can I change the text of the buttons that appear in the function confirm()
of JavaScript?
The default texts are "Accept" and "Cancel". I would like to put "Yes" and "No". Any ideas?
You can make a custom popup or use the sweetalert library, which allows you to customize the messages to be presented.
function confirmFunction() {
swal({
title: "Confirmar Accion",
text: "Se realizara la accion correspondiente",
showCancelButton: true,
confirmButtonColor: '#f7505a',
cancelButtonColor: '#f7505a',
confirmButtonText: "SI",
cancelButtonText: "NO"
}).then(function() {
$('#txt_test').val(idtema);
$('#formTest').submit();
})
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/7.3.5/sweetalert2.all.min.js"></script>
<form name="formTest" id="formTest" method="post">
<input type="button" name="txt_test" id="txt_test" onclick="confirmFunction();" value="Confirmar" />
</form>
According to the standard that defines confirm()
, there is no way to specify custom button labels.
The browser must display an OK / Cancel message to comply with the HTML5 standard.
An alternative is to use a modal
something like this;
$(document).ready(function() {
$('#id_boton').on('click', function () {
myApp.confirm('Estas seguro?', 'Title', function () {
$('.boton_no').text("No");
$('.boton_si').text("SI");
});
});
NOTE: If you use this example you must add Jquery in your project.