Ricardo Ricardo - 1 year ago 76
HTML Question

button href won't redirect

I'm really confused since yesterday I've wrote a Delete button that deletes all the loaded rows from the database and yesterday it worked just fine while today it is not working and I can't find the reason.


<button type="button" class="butDel" onClick="javascript: return confirm('Are you sure?');" href="index.php?startID=<?php echo $firstID; ?>&endID=<?php echo $lastID; ?>">Delete</button>

So I tried to delete each part of the code to see why it doesn't work but it's not working even when I got the JS onClik part off. It is not working when I'm deleting the PHP part and it's not even working when I fill
The problem is it just won't redirect the browser to the location of href.
Tried from a localhost and a live server.

I'm out of ideas.

Answer Source

Put an assignment to window.location in the onclick attribute. You can use an if statement to make it depend on the confirmation.

<button type="button" class="butDel"  onclick="if (confirm('Are you sure?')) window.location.href='index.php?startID=<?php echo $firstID; ?>&endID=<?php echo $lastID; ?>';">Delete</button>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download