How Can I Highlight Text Background When Hovering Over Radio Buttons?

  • Thread starter Thread starter jjiimmyy101
  • Start date Start date
  • Tags Tags
    Radio
Click For Summary

Discussion Overview

The discussion revolves around a coding challenge related to highlighting the background of text labels associated with radio buttons when the mouse hovers over the buttons. The focus is on achieving this effect using HTML and JavaScript, specifically through event handling for mouseover and mouseout events.

Discussion Character

  • Technical explanation
  • Exploratory

Main Points Raised

  • One participant, jjiimmyy101, describes the issue of wanting the text background to highlight when hovering over the corresponding radio button, noting that the current implementation only highlights the text or the button individually.
  • Another participant suggests adding an id to the labels, allowing direct reference to the label properties in the radio button's mouse event handlers, which could solve the problem.
  • jjiimmyy101 expresses gratitude for the suggestion, indicating that they found the solution easy to implement.

Areas of Agreement / Disagreement

The discussion appears to have a resolution with jjiimmyy101 acknowledging the proposed solution, but it does not explicitly confirm whether the solution works as intended or if there are any remaining issues.

Contextual Notes

The discussion does not address potential limitations or edge cases related to the proposed solution, such as browser compatibility or accessibility considerations.

jjiimmyy101
Messages
74
Reaction score
0
This is probably an easy solution, but I can't figure it out for the life of me. I have a bunch of radio buttons with corresponding text right next to it. What I want to happen is that when the mouse is moved over the radio button, I want the text background to get highlighted. As you can see from the code below, I only get the text background highlighted when the mouse is over the text or only the radio button is highlighted when the mouse is over the radio button. How can I fix this? Thanks. -jjiimmyy101


<input type="radio" name="Pizza" onMouseover="style.background='red'" onMouseout="style.background='white'" value="Large" id="Large">

<label for="Large" onMouseover="style.background='red'" onMouseout="style.background='white'">Large</label>

<input type="radio" name="Pizza1" onMouseover="style.background='red'" onMouseout="style.background='white'" value="Small" id="Small">

<label for="Small" onMouseover="style.background='red'" onMouseout="style.background='white'">Small</label>
 
Technology news on Phys.org
Hi jjiimmyy101,

jjiimmyy101 said:
This is probably an easy solution, but I can't figure it out for the life of me. I have a bunch of radio buttons with corresponding text right next to it. What I want to happen is that when the mouse is moved over the radio button, I want the text background to get highlighted. As you can see from the code below, I only get the text background highlighted when the mouse is over the text or only the radio button is highlighted when the mouse is over the radio button. How can I fix this? Thanks. -jjiimmyy101


<input type="radio" name="Pizza" onMouseover="style.background='red'" onMouseout="style.background='white'" value="Large" id="Large">

<label for="Large" onMouseover="style.background='red'" onMouseout="style.background='white'">Large</label>

<input type="radio" name="Pizza1" onMouseover="style.background='red'" onMouseout="style.background='white'" value="Small" id="Small">

<label for="Small" onMouseover="style.background='red'" onMouseout="style.background='white'">Small</label>

If you add an id value to the labels, then you can refer directly to the label properties inside the radio statements (I've called the first label AAA and the second label BBB so you can see my additions easier):



<input type="radio" name="Pizza" onMouseover="AAA.style.background='red'" onMouseout="AAA.style.background='white'" value="Large" id="Large">

<label for="Large" onMouseover="style.background='red'" onMouseout="style.background='white'" id="AAA">Large</label>

<input type="radio" name="Pizza1" onMouseover="BBB.style.background='red'" onMouseout="BBB.style.background='white'" value="Small" id="Small">

<label for="Small" onMouseover="style.background='red'" onMouseout="style.background='white'" id="BBB">Small</label>
 
Gee whiz. At least I knew the answer would be easy. Thank you so much :smile:
-jjiimmyy101
 
jjiimmyy101 said:
Gee whiz. At least I knew the answer would be easy. Thank you so much :smile:
-jjiimmyy101

You're welcome!
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
18
Views
7K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 15 ·
Replies
15
Views
6K
  • · Replies 16 ·
Replies
16
Views
22K
Replies
22
Views
24K