Disabling links

steva
steva used Ask the Experts™
on
What it the best way to disable links?

I have a download link that I would like to gray  out and make it inactive until the user submits a contact form.  I can imagine writing a lot of JavaScript to implement this, but I'm wondering if there's a simply way already out there.

Thanks for any ideas.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Multitechnician
Top Expert 2014
Commented:
Hello steva,

Please have a look to the following :

(to enable the link, click on the button, it will change to "true" value of the boolean "status")
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">var status=false;</script>
</head>
<body>
<a href="http://www.experts-exchange.com" onclick="return status;" style="color:#888888;">Experts Exchange</a>
<br />
<br />
<input type="button" onclick="status=true;" value="Change form status" />
</body>
</html>

Open in new window

Ryan ChongSoftware Team Lead

Commented:
what is the action after the contact form is submitted?

are you using any server side programming language for your portal? if yes then I suggest you can disable the link by server side scripting, instead of javascript, which is a client side scripting.

Author

Commented:
ryancys:

The action after the form is submitted is the visitor selects the enabled link  to download a file. I am using aspx on the server and so could do something from the server, I suppose, but why involve a trip to the server and back when it can all be done in the viewer's browser?

leakim:

Yep.  That'll work!  Thanks.

By the way, I notice that you set the status variable to false in  the header section by
just placing "var status=false;" up there between script tags, without executing
status=false; in an onload function. There's no question that it works here, but I've gotten
into trouble doing that and I'm just wondering when it's safe. The first code below, for example, doesn't
work while the second code does. The flvP and flaP variables being set are used farther down in my markup to access a swf object and they don't get set correctly for the first case below.


       /*    Doesn't work   */

<script type="text/javascript">
   
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    var flvP = (isIE) ? window['flvPlayer'] : document['flvPlayer'];
    var flaP = (isIE) ? window['flaPlayer'] : document['flaPlayer'];
 
  function tryWelcome() { /* called by body onload */
 
      var welcomed = false;
                     *
                     *
                     *

              /* Works  */

<script type="text/javascript">

    var flvP;       // Flash video player.
    var flaP;        // Flash animation player

  function tryWelcome() {  /* called by body onload */
    var isIE = navigator.appName.indexOf("Microsoft") != -1;
    flvP = (isIE) ? window['flvPlayer'] : document['flvPlayer'];
    flaP = (isIE) ? window['flaPlayer'] : document['flaPlayer'];
 
      var welcomed = false;
                      *
                      *
                      *


Thanks for the help.

Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Ryan ChongSoftware Team Lead

Commented:
>>but why involve a trip to the server and back when it can all be done in the viewer's browser?

It's depends on your requirement, one of the reaons why doing it on server side is security reason.

another reason, no need to worry about whether javascript is enabled on browser or the syntax of javascript, as what you facing above.
leakim971Multitechnician
Top Expert 2014

Commented:
If it don't work it's because you work with or on null objects. The object doen't exists, not created, or are not again reacheable.

Author

Commented:
Thanks.
leakim971Multitechnician
Top Expert 2014

Commented:
Thanks for the points!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial