<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.
You need to return true or false from within the onclick:
this will indeed stop default link behaviour when
falseis returned. Only exception: IfdropItem()caused an error. In that case, default link behaviour will apply (i.e. the user will be redirected.)