Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6900957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:36:47+00:00 2026-05-27T07:36:47+00:00

I am trying to make a confirm box which will desire which php code

  • 0

I am trying to make a confirm box which will desire which php code will be executed.
Heres my code:

<script type="text/javascript">
    var answer = confirm('Are you sure?');

    if(answer==true)
       {
          <?php $confirmation = 1; ?>
       } 
    else 
       { 
          <?php define("CONFIRMATION", 1, true); ?>
       }
         alert('<?php echo $confirmation; ?>')
         alert('<?php echo defined("CONFIRMATION"); ?>')
</script>

The problem is , even if i click YES, $confirmation and boolean from defined() function returns 1.
Whatever I click, (cancel or ok) one of them should be 0 (I’ve already declared $confirmation before)
But both of codes at if and else blocks are used!
Normally it works like this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:36:48+00:00Added an answer on May 27, 2026 at 7:36 am

    You fundamentally misunderstand what PHP is doing.

    PHP is evaluated on the server before the page is sent to your browser. By the time the browser sees it and executes the javascript, all the PHP is gone.

    Use your browser’s “view source” on the browser window with this code in it. You’ll see it looks like this:

    <script type="text/javascript">
    var answer = confirm('Are you sure?');
    
    if(answer==true)
       {
                 } 
    else 
       { 
                 }
         alert('1')
         alert('1')
    </script>
    

    You either need to implement what you want to do in javascript to run on the browser, or you need to send a new request to the server and get a new page back (either directly or indirectly) with your response.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

trying to make a page which will recursively call a function until a limit
Im trying to make a function that will return an element of type point:
i've been trying to get a confirm box to work, i am using php
I'm trying to make Selenium 2.4.0 Accept a Javascript generated Confirm-Dialog, using Specflow and
I'm trying to make a console app in c# that will confirm that another
Trying to make a custom :confirm message for a rails form that returns data
im trying to make a popup that comes up to confirm a users action
I am trying to make it so that the user is prompted to confirm
So I am basically trying to make a list of selectable text items (just
I'm trying to create a web app which will check several service status, server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.