Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
php action code not working with javascript confirmAction()

I have this php file which suppose to have a button to do some checkout functionally action by calling a JavaScript built-in function to do it

<a href="index.php" class="btn btn-danger btn-xs" > onclick="confirmAction()" <i class="icon-edit">Check out</a>

I used confirmAction() like this

<script>
                        // The function below will start the confirmation dialog
                        function confirmAction() {
                            let confirmAction = confirm("Dose the maintenance finished yet?");
                            
                            if (confirmAction) {
                                
                                alert("Action Done")
                        
                            } 
                            else {
                                alert("Action canceled");
                            }
                        }
                    </script>

if the user pressed ok I want to do php code which should do post action

controller.php?action=checkout&code=<?php echo $result->CONFIRMATIONCODE; ?>

but I wasn't successful in making it work inside the TRUE case in the javascript function

basically I tried to run the php code without the tag but I failed

any suggestion ? Thanks

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use code like below, if you want to redirect in cancel event then add code like: window.location.href = 'http://www.google.com';

Form:

    <form method="POST" action="controller.php" id="myForm">
  <input type="hidden" name="action" value="checkout"> 
  <input type="hidden" name="code" value="put code here"> 
  <a href="javascript:void(0)" class="btn btn-danger btn-xs" onclick="return confirmAction()" ><i class="icon-edit">Check out</i></a>
</form>

script:

function confirmAction() {
                        let confirmAction = confirm("Dose the maintenance finished yet?");
                        
                        if (confirmAction) {
                            
                            alert("Action Done");
                            document.getElementById("myForm").submit();
                        } 
                        else {
                            alert("Action canceled");
                            return false;
                        }
                    } 
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!