Javascript alert popup with two buttons OK / Cancel or Yes / No

How can I add another button to javascript alert popup window, to have two buttons with values OK / Cancel or Yes / No ?
08 Dec 2020 at 04:44 PM
0give a positive ratinggive a negative ratingshow more
StorStor
Hi,

To get javascript "alert like" box with OK and Cancel button, you have to use confirm() function. It works similar to alert() function, but it displays two buttons with possibility to create positive and negative condition:

<script>
var val = confirm("Type your text here.");
if (val == true) {
alert("You pressed OK.");
} else {
alert("You pressed Cancel.");
}
</script>

09 Dec 2020 at 09:54 AM
0give a positive ratinggive a negative ratingshow more
TimTim
Share on FacebookShare on TwitterShare on LinkedInSend email
Follow us on Facebook
2022 AnswerTabsTermsContact us