When I researched on Google, I always see that they need or use a button for the Javascript to work. But what I need is a confirm popup box without using a BUTTON. like when you run the code, the program will appear instantly.
what I need is a confirm popup box without using a BUTTON. like when you run the code, the program will appear instantly.
(I saw in my classmate's work, he used var ().)
<h1>Demo: confirm() </h1>
<button onclick="save()">Save Data</button>
<p id="msg"></p>
<script>
function save(){
var userPreference;
if (confirm("Do you want to save changes?") == true) {
userPreference = "Data saved successfully!";
} else {
userPreference = "Save Canceled!";
}
document.getElementById("msg").innerHTML = userPreference;
}