make <a href disabled after click once

Discussion in 'JavaScript' started by koemans, Jun 21, 2007.

  1. #1
    I'd like to make the link disable after user click the link!
    now i've the code for it, but it's not working if i use $PHP_SELF!




    here is the href code:

    any idea..?
    Please...help me...!!!
     
    koemans, Jun 21, 2007 IP
  2. ajsa52

    ajsa52 Well-Known Member

    Messages:
    3,426
    Likes Received:
    125
    Best Answers:
    0
    Trophy Points:
    160
    #2
    Try with this:

    
    <html>
    <head>
    <script type = "text/javascript">
      function f_click( t )
      {
        at = t.getAttributeNode("href");
        window.open( at.value );
        t.removeAttributeNode( at );
      }
    </script>
    </head>
    <body>    
      <a href="http://www.google.com" onclick="f_click(this);">Go to Google</a>
    </body>
    </html>
    
    Code (markup):
     
    ajsa52, Jun 22, 2007 IP
  3. Mike H.

    Mike H. Peon

    Messages:
    219
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #3
    koemans:

    I see that you are using: class="link01" within the link, but it doesn't look like it's needed because you are using an image for the link. So, change the class to the PHP_SELF string, as shown:

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>Any Title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script type="text/javascript">
    
    	function noLink(nLink){
    
    		var nHREF = nLink.className;
    		if (nHREF != "")
    			{
    			 nLink.className = "";
    			 //window.open(nHREF);
    			 // or
    			 //self.location.href = nHREF;
    			}
    	}
    	
    </script>
    <style type="text/css">
    
    	 body {background-color:#eae3c6;margin-top:60px}
    	
    </style>
    </head>
    	<body>
    		<a href="#" class="<?echo $PHP_SELF?>?kode_trans_far=<? echo $no_transaksi?>&kode_layanan=<? echo $kode_layanan?>&batal_transaksi=batal_transaksi" onclick="noLink(this);return false"><img src="/images/icon_hapus.gif" alt="Batal Transaksi" border="0"></a>
    	</body>
    </html>
    Code (markup):
     
    Mike H., Jun 22, 2007 IP