如何在包含javascript确认框的变量中保存echo语句?

I have following code

echo '<script type="text/javascript">confirm("Are You Ready To Restore ?");</script>';

Now a confirm box will appears as follows: enter image description here

So when user click on ok the process will continue otherwise it will stop further processing as it cancel it. I want to apply if condition on OK and cancel button . How to save this echo result in variable so that i can apply if condition on it .

How to save this echo result in variable so that i can apply if condition on it .

You can't do that in one http request. You can put Javascript code in your PHP variables, display it but your PHP code will not get the answer to javascript prompt unless you initiate another request, usually via ajax. Or you can take that conditional code to Javascript completely.

PHP is already asleep by the time JavaScript stats working.

You can use if condition inside the script if you click ok it will give you true boolean value or on cancel it will give you false boolean value

<script type="text/javascript">
var x = confirm("Are You Ready To Restore ?");
if(x == true){

}else{

}
</script>