Link to home
Start Free TrialLog in
Avatar of arunatata
arunatata

asked on

Highlight HTML text when a radio button is clicked

Hi,

I have an ASP page with HTML text and a radio button next to it. Everytime the radio button is checked (on), I want the text to be highlighted. For example

ABC                O

I want the text "ABC" to be highlighted if the radio button next to it is selected.

How can this be done?

Thanks,
A.
ASKER CERTIFIED SOLUTION
Avatar of peh803
peh803
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This will turn off any previous selection highlighted while highlighting the current item.

<%@ Language=VBScript %>
<html>
<head>
<script type="text/javascript">
function hilite(v, t) {
  var n;
  var col = document.getElementsByName(v.name);
  for(var i=0; i<col.length; i++) {
    n = t + (i + 1);
    if(document.getElementById(col[i].id).checked == false) {
      document.getElementById(n).style.background = 'white';
      } else {
      document.getElementById(n).style.background = 'yellow';
      }
    }
  }
</script>
</head>
<body>
<span id="text1">text</span><input type="radio" id="radio1" name="radio1" onclick="hilite(this,'text')" /><br />
<span id="text2">text</span><input type="radio" id="radio2" name="radio1" onclick="hilite(this,'text')" /><br />
<span id="text3">text</span><input type="radio" id="radio3" name="radio1" onclick="hilite(this,'text')" /><br />
<span id="text4">text</span><input type="radio" id="radio4" name="radio1" onclick="hilite(this,'text')" /><br />
<span id="text5">text</span><input type="radio" id="radio5" name="radio1" onclick="hilite(this,'text')" /><br />
<span id="text6">text</span><input type="radio" id="radio6" name="radio1" onclick="hilite(this,'text')" /><br />
</body>
</html>

Test page: http://kiddanger.com/lab/ee/q_21495537.asp
@arunatata :

Have you had a chance to try either of the recommended solutions?  Both recommendations seem to suit your needs -- perhaps kiddanger's more fully than the simpler one I suggested.  

Either way, please post back with an update as to whether you still need help, etc.  If so, we'll be happy to continue to help.  If not, please distribute points as you feel appropriate and close the question.

Thank you!
peh803 / Phil
...or send refreshments and dancing girls while we wait.  (O:=
absolutely -- I wouldn't complain about that :)
Avatar of arunatata
arunatata

ASKER

Sorry guys hadn't checked my questions for a while - Phil - I had already used your solution for my program before I saw any of the others so I am awarding you the points. Thanks for a quick response.

Aruna
Glad I was able to help out!

Regards,
Phil / peh803