Reputation: 3182
I have a small piece of javascript to get a user to confirm things on my website. I have a link that I also ask them to confirm before proceeding. I've used the 'onclick' function with buttons no problem, but how do I use it on a link?
Heres my link:
echo"<a href=\"$urlHTML\">Delete</a>";
And heres my 'onclick':
onclick="return confirm('Please confirm you wish to edit these details')"/>
Any help would be great!
Upvotes: 0
Views: 65
Reputation: 11645
You can use onclick on an anchor tag the same way you'd use it on a button:
<a href="<?php echo $urlHTML; ?>" onclick="return confirm('Please confirm you wish to edit these details');">Delete</a>
However you'd be better off using an event handler:
<script type="text/javascript">
function myClickHandler() {
return confirm("Really?");
}
document.getElementById("my_link").onclick = myClickHandler;
</script>
<a id="my_link" href="<?php echo $urlHTML; ?>">Delete</a>
I recommend you also read up on jQuery. It'll save you a lot of time.
Upvotes: 0
Reputation: 119877
You might want to consider using addEventListener and attachEvent (IE) instead of using inline JavaScript.
Upvotes: 0
Reputation: 360842
Ummm...
<?php ?>
<a href="<?php echo $urlHTML ?>" onclick="return confirm(blah blah blah)">Delete</a>
Upvotes: 2