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

  • Thread starter Thread starter jjiimmyy101
  • Start date Start date
  • Tags Tags
    Radio
AI Thread Summary
The discussion revolves around a coding issue where the user wants to highlight the background of text labels associated with radio buttons when the mouse hovers over either the radio button or the label itself. The initial code only highlights the background of the text when the mouse is over the text or the radio button separately. A solution is provided by suggesting the addition of unique IDs to the labels, allowing direct manipulation of the label's background style within the radio button's mouseover events. This approach successfully enables the desired effect of highlighting the text background regardless of whether the mouse is over the radio button or the label. The user expresses gratitude for the simple solution.
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!
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top