LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   color change on checkbox click (https://www.linuxquestions.org/questions/programming-9/color-change-on-checkbox-click-163636/)

akaash 03-29-2004 01:08 AM

color change on checkbox click
 
how can i change the backgroud color of tag whenever i click on the checkbox in it.

I mean as soon as the user checks or unchecks the checkbox then the bgcolor of the corresponding
tag should change.

...just as it is done in yahoo mail,

david_ross 03-29-2004 12:36 PM

I don't use yahoo but why not just look at the source for their page?

You could try something like:
Code:

<HTML>
<HEAD>
<TITLE>Checkbox Example</TITLE>
</HEAD>
<BODY>
<SCRIPT language="javascript" type="text/javascript">
function swapcol(item){
 if(document.getElementById(item).checked){
  document.getElementById(item+'bg').style.background='#00FFFF'
 }
 else{
  document.getElementById(item+'bg').style.background='#FFFFFF'
 }
}
</SCRIPT>
<FORM action="#" name="form">
<DIV id="item1bg">Checkbox 1: <INPUT type="checkbox" id="item1" name="checkbox" onclick="swapcol('item1')"></DIV>
<DIV id="item2bg">Checkbox 2: <INPUT type="checkbox" id="item2" name="checkbox" onclick="swapcol('item2')"></DIV>
<DIV id="item3bg">Checkbox 3: <INPUT type="checkbox" id="item3" name="checkbox" onclick="swapcol('item3')"></DIV>
<DIV id="item4bg">Checkbox 4: <INPUT type="checkbox" id="item4" name="checkbox" onclick="swapcol('item4')"></DIV>
<DIV id="item5bg">Checkbox 5: <INPUT type="checkbox" id="item5" name="checkbox" onclick="swapcol('item5')"></DIV>
</FORM>
</BODY>
</HTML>


akaash 03-29-2004 11:00 PM

Thank u very much it worked..


All times are GMT -5. The time now is 11:09 AM.