How to put prompt, alert and confirm together? I got this already, but i want to add an confirm box after the prompt and alert.. Can someone please help?
<script>
var name = prompt('What is your name?')
alert('Your name is ' + name )
As Patrick suggested in the comments, you need to use the Confirm instead of Alert, clicking Confirm OK will give you value: true ie
<script>
var name = prompt('What is your name?');
var confirm = confirm('Your name is ' + name );
if(confirm === true){
//Your code goes here
}
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
var name = prompt("Please enter your name", "XYZ");
if (name != null) {
alert('Your name is ' + name )
}
}
</script>
</body>
</html>
It will ask your name and comes in alert after giving name to prompt.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.