Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing tables background

Status
Not open for further replies.

taval

Programmer
Jul 19, 2000
192
GB
I have got this code that changes an image from one image to the another when a trigger image is pressed. The thing is a want a tables background to change everytime the trigger image is pressed. I would be very grateful if any one could help me out. Thanks.

----------------------------------------
<script>
arraySrc = new Array();
arraySrc[0] = &quot;images/taha_head.gif&quot;;
arraySrc[1] = &quot;images/taha_head2.gif&quot;;

var x1 = 0;


function change1(target)
{
if(x1 >= arraySrc.length)
{
x1 = 0;
}
document.images[target].src = arraySrc[x1];

x1++;
}

</script>

// trigger image code
<img SRC=&quot;images/arrow_logo.gif&quot; height=100 width=100 onclick=&quot;change1('ben');&quot; >

<img name=&quot;ben&quot; src=&quot;images/taha_head.gif&quot;></td>

-----------------

 
Here is a template you could use...

Code:
<html>
<head>
<style type=&quot;text/css&quot;>
 .bkg1{background-color:#ffff00;}
 .bkg2{background-color:#00ffff;}
</style>
<script language=&quot;javascript&quot;>
 var tblBkg = 1;
 
 function BkgSwitch(){
  if (tblBkg==1){
   tblBkg = 2;}
  else{
   tblBkg = 1;
  }
  document.all.tblDemo.className = &quot;bkg&quot; + tblBkg;
 }
</script>
</head>
<body>
 <table id=tblDemo class=&quot;bkg1&quot;><tr><td>This is a table</td></tr></table>
 <br><input type=button onClick=&quot;BkgSwitch()&quot; value=&quot;Change color&quot;>
</body>
</html>

Later Rob
robschultz@yahoo.com
-Focus on the solution to the problem, not the obstacles in the way.-
 
Thanks Rob, I think the code you have given just changes the background color but I was wondering how on how to change the background images from one to another.
 
You are not actually using background images? set a table cell BG ig like:

<td id=&quot;cell_1&quot; style=&quot;background-image:url('iages/arrow_logo.gif');background-repeat:no-repeat&quot;>

Then you can change these thru a function and changing the property:


document.all.elementID.style.backgroundImage =&quot;url('images/taha_head.gif')&quot;

//or for NN

document.layers.elementID.backgroundImage =&quot;url('images/taha_head.gif')&quot;


I'll leave you to work out the details. Ben
&quot;Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top