Visualizer7
Visualizer7

Reputation: 325

Confirm box not working

<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

Answers (4)

mgraph
mgraph

Reputation: 15338

<input type="button" value="Delete" onclick="show_confirm('http://mydomain.com/delete.php')">

Upvotes: 2

Shyju
Shyju

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

jbabey
jbabey

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

jay
jay

Reputation: 347

no quotes around onclick function
like this : "show_confirm(url)"

Upvotes: 1

Related Questions