Click to See Complete Forum and Search --> : Combo box to change TD cell colour


philosopher1980
10-25-2003, 11:01 AM
Please help, where am I going wrong?
I am trying to change the colour of a table cell using a combo box. It works with buttons, but I can't get it to work with the combo box..

Thanks for your help



<FORM NAME="mycombo">

<SCRIPT LANGUAGE="javascript">

function go()
{
var i = document.mycombo.colour.options[document.mycombo.colour.selectedIndex].value
var l = document.getElementById('page')
// get element table(by id page)
l.style.backgroundColor = i; }
}

</SCRIPT>

<P><SELECT NAME="colour" SIZE="1">
<OPTION VALUE="yellow">Yellow</OPTION>
<OPTION VALUE="red">Red</OPTION>
<OPTION VALUE="blue">Blue</OPTION></SELECT><INPUT TYPE="button" VALUE="Go" ONCLICK="go()"></P>

<P> </P></FORM>

Khalid Ali
10-25-2003, 11:56 AM
Take a look at the code below and see what I have done differently...


<script type="text/javascript">
<!--
function go(){
var frm = document.getElementById("form1");
var i = frm.colour.options[frm.colour.selectedIndex].value
var el = document.getElementById('page')
// get element table(by id page)
el.style.backgroundColor = i;
}
//-->
</script>
</head>

<body class="body">
<form id="form1" action="" onsubmit="" method="post" enctype="text/plain">
<p>
<select name="colour" size="1">
<option value="yellow">Yellow</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
</select>
<input type="button" value="Go" onclick="go()">
</p>
</form>
<table id="page" style="width:100px;height:100px;border:1px red solid;">
<tr>
<td>
Table
</td>
</tr>
</table>

philosopher1980
10-25-2003, 11:59 AM
Thank you very much for your help! now I know where I am going wrong.

Khalid Ali
10-25-2003, 12:51 PM
:D
glad that I could help..