admin管理员组文章数量:1313283
I am trying to alter the background color of a table cell if the selected item in a dropdown is changed. I use the same javascript for a textbox and it works fine. In firebug, "cell" is undefined when called from the select.
Here is my script/html
<html xmlns="" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function changeText(cell, shown, hidden)
{
if (shown == hidden)
{
cell.style.backgroundColor="red";
}
else
{
cell.style.backgroundColor="green";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table cellpadding="5">
<tr>
<td>
Cell 1
</td>
<td>
<select id="catBlah" OnChange="changeText(this.parentnode, this.options[this.selectedIndex].value, '789');">
<option value=""></option>
<option selected="selected" value="789">Item 1</option>
<option value="000">Item 2</option>
<option value="456">Item 3</option>
<option value="123">Item 4</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="text" value="blue" onchange="changeText(this.parentNode, this.value, 'blue');" />
</td>
<td>
Cell 4
</td>
</tr>
</table>
</form>
</body>
</html>
If I just pass the select object (using "this" instead of "this.parentnode"), I can change the select's background color (which might meet requirements), but I can't figure out how to get the parentnode.
Thanks
I am trying to alter the background color of a table cell if the selected item in a dropdown is changed. I use the same javascript for a textbox and it works fine. In firebug, "cell" is undefined when called from the select.
Here is my script/html
<html xmlns="http://www.w3/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function changeText(cell, shown, hidden)
{
if (shown == hidden)
{
cell.style.backgroundColor="red";
}
else
{
cell.style.backgroundColor="green";
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<table cellpadding="5">
<tr>
<td>
Cell 1
</td>
<td>
<select id="catBlah" OnChange="changeText(this.parentnode, this.options[this.selectedIndex].value, '789');">
<option value=""></option>
<option selected="selected" value="789">Item 1</option>
<option value="000">Item 2</option>
<option value="456">Item 3</option>
<option value="123">Item 4</option>
</select>
</td>
</tr>
<tr>
<td>
<input type="text" value="blue" onchange="changeText(this.parentNode, this.value, 'blue');" />
</td>
<td>
Cell 4
</td>
</tr>
</table>
</form>
</body>
</html>
If I just pass the select object (using "this" instead of "this.parentnode"), I can change the select's background color (which might meet requirements), but I can't figure out how to get the parentnode.
Thanks
Share Improve this question asked Jun 28, 2011 at 13:30 monkeypushbuttonmonkeypushbutton 1961 gold badge9 silver badges21 bronze badges2 Answers
Reset to default 5It's parentNode
(note the casing)
I believe that your code was working (I may have fixed it by fiddling with it). It looks like it was your casing. Please see: http://jsfiddle/kaleb/y6UuL/
It appears that you were just not able to see the background color. I added padding to your cell.
本文标签: How to get parentnode of select element in javascriptStack Overflow
版权声明:本文标题:How to get parentnode of select element in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741938644a2406009.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论