Css Background Color Based On Select Value
Hopefully a simple question here. I have the following html code: 
Solution 1:
here: DEMO
<selectid="dropdown"><optionvalue="#00FFFF">Cyan</option><optionvalue="#FF00FF">Magenta</option></select><textarea>Sample Text</textarea>
jquery much easier
    $('#dropdown').change(function(){
       $('textarea ').css('background-color', $(this).val());
    });
Solution 2:
You cannot do this just with HTML and CSS. Some JavaScript is needed. Example:
<selectid="dropdown"onchange="setBg(this)"><optionselectedvalue="#FFFFFF">White</option><optionvalue="#00FFFF">Cyan</option><optionvalue="#FF00FF">Magenta</option></select><textareaid="ta">Sample Text</textarea><script>functionsetBg(sel) { 
  document.getElementById('ta').style.background = 
     sel.options[sel.selectedIndex].value;
}
</script>
Post a Comment for "Css Background Color Based On Select Value"