Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-20-2011, 03:42 PM   PM User | #1
reggiefilho
New to the CF scene

 
Join Date: Dec 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
reggiefilho is an unknown quantity at this point
Random Rotating Avatar/Signature

I came across this on a website, but i wanted to know if i can set a width="150" height="150" parameter somewhere inside this code.
i really am i beginner at this javascript coding:

Code:
<script type="text/javascript">
<!--
var rand=Math.round(Math.random()*4);
var img=new Array(5);
img[0]="1.jpg";
img[1]="2.jpg";
img[2]="3.jpg";
img[3]="4.jpg";
img[4]="5.jpg";

document.write("<img src=\"" + img[rand] + "\" />");
//-->
</script>

Last edited by reggiefilho; 12-20-2011 at 03:44 PM.. Reason: wrong [code][/code] script
reggiefilho is offline   Reply With Quote
Old 12-20-2011, 04:05 PM   PM User | #2
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
This work for you?:

Code:
document.write("<img width=\"150\" height=\"150\" src=\"" + img[rand] + "\" />");
__________________
Regards, R.J.
chump2877 is offline   Reply With Quote
Old 12-20-2011, 05:36 PM   PM User | #3
reggiefilho
New to the CF scene

 
Join Date: Dec 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
reggiefilho is an unknown quantity at this point
Some one replied to my post somewhere else and gave me another code.. is there a way to add the width and height parameters to this:
Code:
<table id="tst">
<tbody>
<tr>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i897.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i885.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i877.jpg" alt="" /></td>
</tr>
<tr>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i876w.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i856w.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i856.jpg" alt="" /></td>
</tr>
<tr>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i776w.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i776.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i465.jpg" alt="" /></td>
</tr>
<tr>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i1.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i9.jpg" alt="" /></td>
<td><img src="http://i1083.photobucket.com/albums/j400/ReggieAzevedoFilho/i335.gif" alt="" /></td>
</tr>
</tbody>
</table>
<p><script type="text/javascript">
/*<![CDATA[*/

function Random(id){
 var table=document.getElementById(id),imgs=table.getElementsByTagName('IMG'),ary=[],z0=0,z1=0;
 for (;z0<imgs.length;z0++){
  ary[z0]=imgs[z0].src;
 }
 ary=ary.shuffle(ary);
 for (;z1<imgs.length;z1++){
  imgs[z1].src=ary[z1];
 }
}

Array.prototype.shuffle=function(ary){
  for (var r,t,z0=0;z0<ary.length;z0++){
   r=Math.floor(Math.random()*ary.length);
   t=ary[z0];
   ary[z0]=ary[r];
   ary[r]=t;
  }
  return ary;
 }


Random('tst')
/*]]>*/
</script></p>
reggiefilho is offline   Reply With Quote
Old 12-20-2011, 06:58 PM   PM User | #4
chump2877
Senior Coder

 
chump2877's Avatar
 
Join Date: Dec 2004
Location: the U.S. of freakin' A.
Posts: 2,530
Thanks: 15
Thanked 128 Times in 121 Posts
chump2877 is on a distinguished road
Like this maybe?

Code:
function Random(id){
 var table=document.getElementById(id),imgs=table.getElementsByTagName('IMG'),ary=[],z0=0,z1=0;
 for (;z0<imgs.length;z0++){
  ary[z0]=imgs[z0].src;
 }
 ary=ary.shuffle(ary);
 for (;z1<imgs.length;z1++){
  imgs[z1].src=ary[z1];
  imgs[z1].style.width='150px';
  imgs[z1].style.height='150px';
 }
}
Of course, if your goal is just to set all image sizes to 150x150 px, then you'd be better off using some CSS:

Code:
#tst img {width:150px;height:150px;}
__________________
Regards, R.J.
chump2877 is offline   Reply With Quote
Users who have thanked chump2877 for this post:
reggiefilho (12-20-2011)
Old 12-20-2011, 09:35 PM   PM User | #5
reggiefilho
New to the CF scene

 
Join Date: Dec 2011
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
reggiefilho is an unknown quantity at this point
perfect! it worked great! thank you!
reggiefilho is offline   Reply With Quote
Reply

Bookmarks

Tags
avatar, javascript, random, refresh, resize

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:49 AM.


Advertisement
Log in to turn off these ads.