javascript - Function to return true in OnClick with SweetAlert -


hi i'm doing function in php, in ask confirmation continue using sweetalert, idea use onclick event, problem have no control, message displayed not expect confirmation in of both cases, form , link.

code:

<meta http-equiv="content-type" content="text/html; utf-8" />  <script src="scripts/jquery-1.4.4.min.js"></script> <script src="sweetalert/dist/sweetalert-dev.js"></script> <link rel="stylesheet" href="sweetalert/dist/sweetalert.css">  <body>  <?php  function showmessage($titulo,$contenido,$tipo) {     if($tipo=="ok") {         //     }     else if($tipo=="error") {         //     } else if($tipo=="ask") { echo " swal({   title: '$titulo',   text: '$contenido',   type: 'warning',   showcancelbutton: true,   confirmbuttoncolor: '#dd6b55',   confirmbuttontext: 'yes, delete it!',   cancelbuttontext: 'no, cancel plx!',   closeonconfirm: false,   closeoncancel: false }, function(isconfirm){   if (isconfirm) {     return true;   } else {     return false;   } }); ";     } else {      } }  ?>  <a href='http://www.google.com' onclick="<?php showmessage("test","test","ask"); ?>">go</a>  <form action="http://www.google.com"> <input type="submit" name="none" text="test" onclick="<?php showmessage("test","test","ask"); ?>"> </form>  </body> 

someone me?

<?php showmessage("test","test","ask"); ?> 

is being called on page load.

you cannot call php functions based on browser events without ajax.

showing confirm message better done through use of javascript.

try like

<input type="submit" name="none" text="test" onclick="checkconfirm('test')"> <script> checkconfirm(message) {     var confirm = confirm(message);     if (confirm == true) {         // user said yes     } else {         // user said no     } } </script> 

edit ah, took @ implementation.

here can achieve result you're looking for:

<input type="submit" name="none" text="test" onclick="showmessage(<?php echo $titulo ?>, <?php echo $contenido ?>, <?php echo $tipo ?>)"> <script>   showmessage(title, text, tip) {     if (tip == 'ask') {       swal({         title: title,         text: text,         type: 'warning',         showcancelbutton: true,         confirmbuttoncolor: '#dd6b55',         confirmbuttontext: 'yes, delete it!',         cancelbuttontext: 'no, cancel plx!',         closeonconfirm: false,         closeoncancel: false       },       function(isconfirm){         if (isconfirm) {           return true;         } else {           return false;         }       });     }   } </script> 

i still recommend ajax , purpose of it. wrap head around full stack.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -