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\');">
</form>
'; ?>
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="http://sdfsdfs.com?keepThis=true&TB_iframe=true&height=10&width=1200&x=2342342&enter_other_room=2" 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?
- http://jsfiddle.net/8CDc5/1/
JS
$('.customClick').on('click', function() {
var str = $(this).attr('data-str');
str = (str == '0')? 'Are you sure?' : str;
return (confirm(str))? true : false;
});
HTML
<a href="http://jsfiddle.net/8CDc5/" class="customClick" data-str="0">Test</a>
Related Topics
Set Focus to the Next Input Element
Vue.Js Refs Are Undefined, Even Though This.$Refs Shows Theyre There
How to Compare Two Arrays Using Lodash (The Order Matters)
How to Get Route Url Params in a Page in Nuxt2 and 3
How to Fix Problem Closing Dropdown When I Click Outside It
Can We Call the Function Written in One JavaScript in Another Js File
How to Separate an Integer into Separate Digits in an Array in JavaScript
How to Align Text Input Correctly in React Native
How to Loop Over Object Properties With Ngfor in Angular
How Does Group by Works in Sequelize
Angular:How to Add/Remove Files in the Angular
How to Implement Multiple Checkbox Using React Hook
Bootstrap Modal Only Showing Backdrop
How to Make a Modal Popup to Take an Input Value Using Jquery or JavaScript