dqrzot2791 2015-04-01 19: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 19: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条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器