I am going to have a hidden value on my web page. If it contains a certain value (5 in this case), when a link is clicked, rather than executing the link, I would like an alert to display. Is there a way to do this?
I was thinking of having a JavaScript function something like this:
function validateLink()
{
if (document.myform.myfield.value == "5")
{
alert("You cannot visit this page");
}
}
Then doing something like this
<a href="www.mypage.com" onclick =validateLink()">My link </a>
Is there a way if the alert in validate link is displayed to not direct the user to www.mypage.com?
Thank you so much!
Tags: