0
votes

i have a hyperlink code like : Click Here and i want to customize this link on the basis of my radio button click,which are like : YES NO on radio-button value:'yes',i want to enable the hyperlink. while on radio-button value:'no',i want to disable the hyperlink. So,to make the hyperlink disable after clicking radio-button 'NO', i have written the following in disable-link() method : function disable-link() { //document.getElementById('disable-link').disabled=true; document.getElementById('disable-link').href = '#'; } Now,what i have to write in enable-link() method so that the hyperlink gets re-enabled after clicking radio-button 'YES'

function enable-link()
{
    //document.getElementById('disable-link').disabled=false;
        // SOME LINE OF CODE TO RE-ENABLE THE LINK
}

document.getElementById('disable-link').disabled=true*/*false; -: it makes the disable but user is able to click on the hyperlink though.So, i have used "document.getElementById('disable-link').href = '#';" -: it makes the link unclickable too Please suggest.

1

1 Answers

5
votes
<!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" />
<title>StackoverFlow answer for question</title>
<script type="text/javascript">

    var link,color;

 function disable_link() { 

  document.getElementById('testlink').disabled=true;

  link = document.getElementById('testlink').href;

  document.getElementById('testlink').removeAttribute('href');
  //document.getElementById('testlink').style.color = "grey";

   } 


 function enable_link() { 

  document.getElementById('testlink').setAttribute("href",link);

   } 


</script>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
  <p>
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0" onchange="disable_link();" />
      Radio</label>
    <br />
    <label>
      <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_1" onchange="enable_link();" />
      Radio</label>
    <br />
  </p>
  <a id="testlink" href="http://www.yahoo.com"> test </a>
</form>
</body>
</html>