Lock links after first click on a link?

How do I do the following:
I want to use javascript to lock the links of a page, once a link was clicked.
Since it's my page, I don't have to use real links (although if possible it's prefered).

Example:
Say there are two links on my page:
http://www.ibm.com
and http://www.microsoft.com

Now once the first link is clicked I want the others to become inactive.

ADVAthanksNCE,  Moshe
PS. I'll give the question more points as they come...
LVL 2
mflamAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

xabiCommented:
ok, you can "lock" links using Javascript, but if you reaload the page all the info saved about the locked links will be lost. Anyway you can only lock the links that open a page in a window or in another frame. Imagine you have two frames. 1 with the links and the other with the contens. The links will be something like:

<a href="javascript:open_link('foo.htm')">Link 1</a>

and your javascript will be something like:

<script language="javascript">
<!--
var locked = false
function open(new_url) {
  if (!locked) {
    locked = true
    // open the link
  } else {
    alert("Locked")
  }
}
//-->
</script>

As you can see I store the info in the var locked, but if you reload the page the variable will be initialized again.

xabi
0
drajendranCommented:
Do you use frames?
0
mflamAuthor Commented:
Here's what I figured out myself meanwhile:
===============================
Using onClick and return(false)
===============================

If I write:

<a href=http://www.ibm.com
onClick="if (locked) return(false) else { locked = true; return(true)}
IBM </a>

It works for all links!

But if I use:

<a href=http://www.ibm.com
onClick="linkOnce()"
IBM </a>

and in the javascript section after the var: locked = false I add:

linkOnce()
{
  if (true == locked)
      return(false)
  else
  {
      locked = true;
      return(true);
  }
}

This for some reason does not work!
Can someone tell me how to fix it?

ADVAthanksNCE, Moshe  

0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

nericsonCommented:
You may be having a scope problem.  I have had things like this happen before.  "debugger" should tell you here.

I think I fixed it w/ an eval().

Another way to do it (w/ some browsers) is innerHTML (or outer or Text).  Change it to <A id=IBM name=IBM href="">bla</A>.
0
KeClCommented:
mflam: It's easy: instead of

<a href=http://www.ibm.com
onClick="linkOnce()"
IBM </a>

write:

<a href=http://www.ibm.com
onClick="return linkOnce()"
IBM </a>

with the same function as you told above.

Good luck!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KeClCommented:
Exactly your code may look like this (I forgot '>' after <a href=http://www.ibm.com
onClick="return linkOnce()" in previous comment) :


<html>
<head>
<title></title>
<script>
var locked = false;
function linkOnce()
{
if (locked)
return(false)
else
{
locked = true;
return(true);
}
}
</script>
</head>
<body>
<a href="javascript:alert('click');"
onClick="return linkOnce()">IBM</a>
<a href="javascript:alert('click');"
onClick="return linkOnce()">MBI</a>
</body></HTML>
0
mflamAuthor Commented:
And a friend of mine showed me how the code could be even more elegant using a return of "isFirstClick"! instead of "isLocked".

Thanks!  Moshe
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.