Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

165
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda