get value onclick
<button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var x; if (confirm("Press a button!") == true) { x = "You pressed OK!"; } else { x = "You pressed Cancel!"; } document.getElementById("demo").innerHTML = x; } </script>