JavaScript Program to Change Text Color on Checkbox Selection

Write a JavaScript program to change text color on checkbox selection.



Source Code
<html>
<head>
    <title>Text color change RGB</title>
    <script>
        function setOptions()
        {
            var panel = document.getElementById('panel')
            with(document.forms.myform)
            {
                var selection="You selected colors: ";
                var r=0, g=0, b=0;

                if(red.checked == true)
                {
                    selection += "Red";
                    r = 255;
                }
                if(green.checked == true)
                {
                    selection += ", Green";
                    g=255;
                }
                if(blue.checked == true)
                {
                    selection += ", Blue";
                    b=255;
                }
                panel.innerHTML = selection
                panel.style.color = rgb1(r, g, b)
            }	
        }	
        function rgb1(r, g, b)
        {
            var text = ((r==255) ? "FF" : "00") + ((g==255) ? "FF" : "00") + ((b==255) ? "FF" : "00")
            return "#"+text
        }
    </script>
</head>

<body>

<form name="myform">
    <input type="checkbox" name="red" onchange="setOptions()">Red<br/>
    <input type="checkbox" name="green" onchange="setOptions()">Green<br/>
    <input type="checkbox" name="blue" onchange="setOptions()">Blue<br/>
</form>

<p id="panel">You selected colors: </p>
</body>
</html>
Output