PDA

View Full Version : Change A Table BG Color From A Image Button



scarrface
03-17-2008, 06:03 PM
ok i need some help coding a script...i want to be able to change a table bg image not its color from a another image *Button*..there are 6 buttons, different colors, i want the background image of a table change to each button color that is clicked...the buttons will be at the top and the table image i want to be able to change will be under the buttons....is this possible? please help

Nile
03-18-2008, 01:03 AM
Does this help you?


<script type='text/javascript'>
function change_bg(hex, id){
document.getElementById(id).style.background="#"+hex;
}
</script>
<button onClick="change_bg('0000A5','table_d');">Color1</button> <button onClick="change_bg('7272A3','table_d');">Color2</button>
<button onClick="change_bg('FF967C','table_d');">Color3</button>
<table width="500" height="500" id="table_d"><tr><td></td></tr></table>

Now, all you need to do is add buttons, you should do it like this(the onClick).

cahnge_bg('hex_code_without_#','id')