简体   繁体   中英

Executing PHP Code in Javascript with Confirm()

I am trying to use javascript's confirm function to set my php variable $continue based on the confirm click. I feel like the code below should work, but $continue is always false.

    <script type="text/javascript">
    <!--
    var answer;
    answer = confirm("Do you want to continue?");
    if (answer) { <?php $continue = true; ?> }
    else { <?php $continue = false; ?> };

    // -->
    </script>

Any help is always appreciated!

php is server side, javascript is client side.

if you need to change something via javascript do this using ajax. but you need keep this in your mind: the php just write html and process http requests. all of the interaction in the client side who will change some state in the server must perform a http request.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM