in alert message in django i want to display yes or no instaed of oj and cancel is taht…
- User
in alert message in django i want to display yes or no instaed of oj and cancel is taht possible
- Assistant
Yes, it is possible to display "yes" or "no" instead of "ok" and "cancel" in an alert message in Django. You can use custom JavaScript code to replace the default button text with your own text. Here is an example:
<script> window.alert = function(message) { var response = confirm(message); if (response === true) { alert("yes"); } else { alert("no"); } }; </script>You can add this script to your Django template or to your static files and include it in your HTML file. When an alert message is triggered, it will display a dialog box with the text of the message and two buttons labeled "yes" and "no". The user can click one of the buttons to respond to the message, and the script will return either "yes" or "no" as the response.
- User
$('.children').click(function(){
if(confirm("Do You Have Children ?")) {
$('#children-tab').prop('checked', true);
}else{
return false;
}
}) here i want to display yes or no instaed of ok and cancel
- Assistant
You can modify the confirmation dialog to display "yes" or "no" instead of "ok" and "cancel" by customizing the buttons using the
confirm()function. Here's an example:$('.children').click(function(){ if(confirm("Do You Have Children ?", "Yes", "No")) { $('#children-tab').prop('checked', true); } else { return false; } });In this script, the
confirm()function has three arguments: the message to display ("Do You Have Children?"), the label for the "Yes" button ("Yes"), and the label for the "No" button ("No"). When the user clicks one of the buttons, the function will return eithertrueorfalsedepending on which button was clicked. If the "Yes" button is clicked, the#children-tabbox will be checked; otherwise, nothing will happen. - User
('.children').click(function() { if(confirm("Do you have children?")) { ('#children-tab').prop('checked', true); ('.children-status').text('Yes'); } else { ('.children-status').text('No'); } }); for this code i want to display tet yes or no insted of ok and cancel
- Assistant
To display "yes" or "no" instead of "ok" and "cancel" in a confirmation dialog, you can customize the buttons using the
confirm()function like this:$('.children').click(function() { var confirmation = confirm("Do you have children?", "Yes", "No"); if (confirmation == true) { $('#children-tab').prop('checked', true); $('.children-status').text('Yes'); } else { $('.children-status').text('No'); } });In this modified code, the
confirm()function has three arguments: the message to display ("Do you have children?"), the label for the "Yes" button ("Yes"), and the label for the "No" button ("No").When the confirmation dialog is displayed, the user will see two buttons labeled "Yes" and "No" instead of the default "ok" and "cancel". If the user clicks "Yes", the
#children-tabcheckbox will be checked and the text "Yes" will be displayed in the.children-statuselement. If the user clicks "No", the text "No" will be displayed in the.children-statuselement. - User
not working give me clean code again
- Assistant
I apologize for the confusion in my previous response. The
confirm()function in JavaScript does not allow to customize the button labels. Instead, you can use a plugin like SweetAlert to achieve this functionality. Here's how you can modify your code with SweetAlert: