javascript - Cannot call function on click -
i beginner in php, want show confirm box on link click cannot result in that. gives me error onclick cannot read error because refreshes page. there mistake in single quote?
is possible me use alert in link tag?
echo '<tr><td align="center"><a onclick="confirm return("you want delete?");" href="persontype.php?person_type_id='.$postrow['person_type_id'].'">delete</a></td>';
you need escape quote, use javascript:
, it's return confirm()
, not confirm return()
echo '<tr><td align="center"><a onclick="javascript: return confirm(\'you want delete?\');" href="persontype.php?person_type_id='.$postrow['person_type_id'].'">delete</a></td>';
i copied exact php code , modified. above php code should output exact functionality expecting.
to show sweetalert:
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script> <script src="http://t4t5.github.io/sweetalert/dist/sweetalert.min.js"></script> <link rel="stylesheet" href="http://t4t5.github.io/sweetalert/dist/sweetalert.css"> <?php echo '<tr><td align="center"><a onclick="javascript: swal({title:\'you want delete?\', text: \'you want delete user?\', type: \'warning\', showcancelbutton: true, confirmbuttoncolor: \'#dd6b55\', confirmbuttontext: \'yes, delete it!\', cancelbuttontext: \'no, cancel plx!\', closeonconfirm: false, closeoncancel: true }, function(isconfirm){ if (isconfirm) { window.location.href = \'persontype.php?person_type_id='.$postrow['person_type_id'].'\'; } else { return false; } }); return false;" href="persontype.php?person_type_id='.$postrow['person_type_id'].'">delete</a></td>';
sorry, code looks ugly in 1 line, works , it's way show sweet alert inside link.
Comments
Post a Comment