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 9265889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:11:19+00:00 2026-06-18T14:11:19+00:00

PHP is executed first before JS, but is there an easy way to output

  • 0

PHP is executed first before JS, but is there an easy way to output a confirmation dialog (like Javascript confirmation) if the data is not empty like in this conditional PHP statement:

<?php
if (!empty($data)) {

//data is not empty
//Ideally I want to show a confirmation dialog in this part to the user
//to confirm if the user wants to overwrite the existing data

//If the user confirms
//Overwrite the existing data here

} else {

//data is empty,proceed to other task
//don't show any dialog

}

I don’t want to add another form to the user, just a simple confirmation dialog like the JS confirm. Or is there a PHP replacement function for this? Thanks.

  • 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-06-18T14:11:21+00:00Added an answer on June 18, 2026 at 2:11 pm

    I like to separate the data and the code, so I like to create a JS variable from PHP

    // I always use json_encode when creating JS variables from PHP to avoid
    // encoding issues with new lines and quotes.
    var isDataEmpty = <?php echo json_encode(empty($data)); ?>;
    
    if (!isDataEmpty) {
       if (confirm("Some message")) {
          overwriteExistingData();
       }
    } else {
       // proceed
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there anyway to register a PHP callback function to be executed when the
I red there's a limit for a PHP script to be executed and I
Via PHP, i'm generating some JavaScript code, witch looks like this: <script type=text/javascript> $(window).load(function()
When using the php include function the include is succesfully executed, but it is
I have three update statements to be executed in PHP, i am getting the
I have a very expensive query which gets executed from php and it can
on $(document).ready(function() in index.php, the below AJAX is executed, running the file getData.php: if
Does it possible to execute php file and store its output into some variable?
Can anybody help me understand why are there two loops here? <?php // create
I have already asked this before but I never seem getting how it works(I

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.