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条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?