HTML-从mysql生成的选择框内的选项更改文本区域的颜色 [英] HTML - changing color in text area from an option inside of a select box generated from mysql
问题描述
我一直在尝试搜索与我想要的东西相似的东西,但似乎无法获得确切的解决方案.我绝不是HTML编码员,但我必须用HTML做一些工作,所以我正在学习.我了解我的代码可能有点混乱/不需要,因此请原谅我.我设法找到了一些类似的JavaScript,因此您将在下面看到它.
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.
- 首先,我创建了一个表格,其中的选择框和文本区域插入到单元格中.
- 选择框是从MySQL生成的(因此也使用PHP).
- 当我从该选择框中选择特定选项时,我希望在其他单元格中更改文本区域背景.
- 我给了文本区域一个ID,以便可以做到这一点.
我目前可以使用:
<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.
推荐答案
您尚未为元素赋予ID,而已为其赋予CLASS.因此getElementById()将无法正常工作.更改html以添加ID而不是CLASS.
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.
这篇关于HTML-从mysql生成的选择框内的选项更改文本区域的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!