Reputation: 325
<input type="button" value="Delete" onclick=show_confirm(http://mydomain.com/delete.php)>
I have this button and this JavaScript function, but they don't work. When I click the button, nothing happens. What is wrong with my code?
function show_confirm(url){
var r = confirm("Do you want to delete this?");
if (r == true){
window.navigate(url);
}
else{
alert("You pressed Cancel.");
}
}
Upvotes: 0
Views: 364
Reputation: 15338
<input type="button" value="Delete" onclick="show_confirm('http://mydomain.com/delete.php')">
Upvotes: 2
Reputation: 218732
Pass the url inside double quotes.
<input type="button" value="Delete" onclick=show_confirm("http://mydomain.com/delete.php")>
Working sample : http://jsfiddle.net/93QWJ/
Upvotes: 3
Reputation: 46647
Your html is not well formed.
<input type="button" value="Delete" onclick=show_confirm(http://mydomain.com/delete.php)>
should be
<input type="button" value="Delete" onclick="javascript:show_confirm('http://mydomain.com/delete.php');" />
The javascript:
is only necessary if you also have VBScript on the page, but it's a good habit to be in.
Upvotes: 3