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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:15:33+00:00 2026-05-24T23:15:33+00:00

Here is the Javascript code, just for test: <script type=text/javascript> function show_confirm() { var

  • 0

Here is the Javascript code, just for test:

<script type="text/javascript">
    function show_confirm()
        {
            var r=confirm("Are you sure?");
            if (r==true)
            {                   
            }
            else
            {                    
            }
        } 
</script>

And this is the php code:

<form action="Test.php" method="post">
    <input type="text" name="test"/>
    <input type="submit" value="submit" onclick="show_confirm()"/>
</form>

So if the submit button is clicked, a confirm box will pop out. And if “OK” button is clicked, the page will be redirected to Test.php and post method will be executed, like a normal php page submit operation. Or else, if the “cancel” button is clicked, i want it stay the same page and post method won’t be executed. Is this function can be implemented and how to modify the code? I know PHP is for server and JS is for client. I’m not sure if I can mix them like this. Or I should use Ajax? Thanks for help!

  • 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-24T23:15:34+00:00Added an answer on May 24, 2026 at 11:15 pm

    The best way to do this is as follows:

    <script>
        function show_confirm(){
            return confirm("Are you sure?");
        }
    </script>
    <input type="submit" onclick="return show_confirm();">
    

    The reason I use show_confirm instead of the built-in function directly is because if you want to change the functionality of the confirm popup, it is much harder if you are using the builtin function everywhere in your code.

    Abstracting out this kind of functionality and writing clear, simple code like this will make you a better programmer 🙂


    warning: as indicated in my comments below, this will only work if the user explicitly clicks the submit button. If the user submits the form by some other method, the confirm box will not show. See http://www.w3schools.com/jsref/event_form_onsubmit.asp if you want to show a confirm regardless of how the form was submitted.

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

Sidebar

Related Questions

Trying to truncate some code here and running into a problem: <script type=text/javascript> $(function()
I need to make javascript code to swap images with option change. Here is
I'm having some trouble with the jQuery hover method. Here's the relevant JavaScript code:
I am using pseudo-code here, but this is in JavaScript. With the most efficient
I am using the jquery tooltip and here is the code for it Javascript
I am trying to insert php variables into javascript. Here is the broken code:
I have a little bit of Javascript that almost works correctly. Here's the code:
I try to us wp_enqueue_script to load my javascript, here is my code: <?php
here's the sample code (fully working - just copy to an empty html file
Here is my simple code to try and test if jQuery resizable is working.

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.