/    Sign up×
Community /Pin to ProfileBookmark

Combo box to change TD cell colour

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

[QUOTE]

<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>[/QUOTE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliOct 25.2003 — Take a look at the code below and see what I have done differently...

[code=php]
<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>
[/code]
Copy linkTweet thisAlerts:
@philosopher1980authorOct 25.2003 — Thank you very much for your help! now I know where I am going wrong.
Copy linkTweet thisAlerts:
@Khalid_AliOct 25.2003 — ?

glad that I could help..
×

Success!

Help @philosopher1980 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...