dqrzot2791 2015-04-01 11:21
浏览 118
已采纳

HTML - 从mysql生成的选择框内的选项更改文本区域中的颜色

I have been trying to search for things similar to what I want but can't seem to get the exact solution. I am in no way a HTML coder, but I have to do some work in HTML, so I am learning. I understand that my code is probably a bit messy/unneeded, so please forgive me. I have managed to find some similar javascript so you will see this below.

  • First I have a table created with select boxes and text areas inserted into the cells.
  • The select boxes are generated from MySQL (so am using PHP also).
  • When I select a specific option from that select box, I want my text area background to change, in a different cell.
  • I have given the text area's an ID so that this can be made possible.

I currently can use this:

<select  onChange="updateColor(this.options[this.selectedIndex].value);"  name="sunday combo" id="Suncombo2">
    <option value= " " selected="selected">Please Select</option>
    <option value="FFFFCC">light yellow
    <option value="CCFFFF">light blue
    <option value="CCFFCC">light green
    <option value="CCCCCC">gray
    <option value="FFFFFF">white'

    Javascript: 
<SCRIPT LANGUAGE="JavaScript">
function updateColor(color){
    var myCell = document.getElementById('2ndInputSun');     
        myCell.style.background = "#"+color;

}

HTML:

<tr class="5row">
<td class="2ndInputMon"><textarea></textarea></td>
<td class="2ndInputTues"><textarea></textarea></td>
<td class="2ndInputWed"><textarea></textarea></td>
<td class="2ndInputThurs"><textarea></textarea></td>
<td class="2ndInputFri"><textarea></textarea></td>
<td class="2ndInputSat"><textarea></textarea></td>
<td class="2ndInputSun"><textarea></textarea></td>

However, when I insert all this, I get no change in colour from the text area.

展开全部

  • 写回答

2条回答 默认 最新

  • doujiang1832 2015-04-01 11:31
    关注

    You have not given the elements an ID you have given them a CLASS. so getElementById() will not work. Change the html to add the ID not the CLASS.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部