Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Onclicks for links? 2

Status
Not open for further replies.

fpgiv

Programmer
Oct 1, 2003
91
US
Hi,
I have several hyperlinks on my pages, and if a user clicks on them, I want them to be sure they are doing what they want to do. I wrote the following, but withough the href property in the <a> tag, the text doesn't appear as a link, and the mouse doesn't change either.
Can anyone lend any insight into what I can do to make this happen?
Thanks!
--Phil
<script language="javascript">

function callalert(wheretogo)
{
if (confirm("Are you sure you want to do this?"))
{
location=wheretogo;
}
}
</script>

<a class="mylink" name=" onclick="callalert(this.name)">Test Me</a>
 
Hi rsshetty,
Well, that makes the link look like the other links, but the problem with that is the even if a person clicks cancel, the page still navigates away. That's why I took out the href in the first example.
--Phil
 
Instead of using location, let the anchor tag use it's inherent href to redirect the page. However, return true or false to the anchor to determine whether or not to navigate to another page. This will also allow you to see the link location in the taskbar. Here's a working example:
Code:
<html>
<head>
<title>Blah</title>
<script language=JavaScript>
function callalert() {
   return (confirm("Are you sure you want to do this?"));
}
</script>
</head>
<body>
<form name=blahForm>
<a class="mylink" href="[URL unfurl="true"]http://www.tek-tips.com"[/URL] onclick="return callalert()">Test Me</a>
</form>
</body>
</html>

-kaht

banghead.gif
 
This is a little more compact.

<a class="mylink" href=" onclick="javascript:return (confirm('Are you sure you want to do this?'));">Test Me</a>

rsshetty.

It's always in the details.
 
Oh well, I realized that and revised it a bit. Guess kaht helped you out anyway.
As for the links looking like other links, what I normally do is put the text within <font> tags and define my own classes.

rsshetty.

It's always in the details.
 
Thanks guys! I didn't realize that the trick all along was returning true/false to the <a>. This is a major lifesaver!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top