Reputation: 14568
<a href="/delete/<?php echo $prod_name; ?>" onClick="dropItem()">delete</a>
Now is it true that only if the function dropItem return true will the page be redirected to the url given in the href attribute? If not then can anyone suggest any method to implement this kind of thing. i.e only when the java script returns true the page redirection happens.
Upvotes: 0
Views: 111
Reputation: 449385
You need to return true or false from within the onclick:
onclick="return dropItem();"
this will indeed stop default link behaviour when false
is returned. Only exception: If dropItem()
caused an error. In that case, default link behaviour will apply (i.e. the user will be redirected.)
Upvotes: 2