Php - Return Confirm Within PHP Issue

Return Confirm() in php

' quatation will not work in string since you started string with single quatation try to escape with \
like \'

try this

<?php echo '
<form method = "post" onsubmit="return confirm(\'test\');">
'; ?>

on click confirm inside php echo

Instead of using location.href to do the redirect, you could just put the link in the href. If they click OK it will redirect them.

Something like this.

echo "<td><a href='country.php?delete&id=".$row['id']."' onclick='return confirm(\"Are you sure you want to do this?\")'>delete</a></td>";

Edit: typos

Onclick confirm() not working when echoed by PHP

You can't escape quotes inside HTML attributes, so onclick="confirm(\"...\");" won't work. Put single quotes around the string. And since it's inside a PHP single-quoted string, you need to escape them for PHP.

And since the string contains an apostrophe inside it, you need to escape that for Javascript. You have to double the backslashes to get a literal backslash into the PHP string. And a third backslash to escape it for PHP.

echo '<a href="" class="box" TARGET="_self" oncontextmenu="return false;" onclick="confirm(\'Are you sure you want to enter the users\\\'s Room?\');\">User\'s Room</a>';

Onclick return confirm not working in Jquery Mobile?

Does something like this work for you?



$('.customClick').on('click', function() {
var str = $(this).attr('data-str');
str = (str == '0')? 'Are you sure?' : str;

return (confirm(str))? true : false;


<a href="" class="customClick" data-str="0">Test</a>​

Related Topics

Leave a reply