PDA

View Full Version : Something is effecting the spacers in this code . . .


The-Ensemble
07-26-2006, 08:38 PM
I created a scheme with a random image generator (via javascript/html) inside it.
and something seems to making the spacers just go so the forums are full width. i can't get them to go to the size i want is there something in this code that could effect the spacers?:
<script language="JavaScript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
document.writeln('<td'+' border=0 ><img src="'+xoxo[choice]+'" align=right height=253 width=486 border=0 ><'+'/td>');
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>

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

<script language="JavaScript" type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS

var ic = 2;
var xoxo = new Array(ic);

xoxo[0] = "";
xoxo[1] = "";

function pickRandom(range) {
if (Math.random) {
return Math.round(Math.random() * (range-1));
}
else {
var now = new Date();
return (now.getTime() / 1000) % range;
}
}

var choice = pickRandom(ic);
// STOP HIDING FROM INCOMPATIBLE BROWSERS --></script>
<script type="text/javascript" src="clientscript/vbulletin_global.js"></script>

Code Monkey
07-27-2006, 02:33 AM
You should be using DOM for this.


//find the row you want to atach the image to.
target_row = document.getElementById('target_rows_id');
img_col = document.createElement('td');
img_col.style.border = 0;

new_img = document.createElement('img');
new_img.setAttribute('src') = xoxo[choice];
new_img.style.align = 'right';
new_img.style.height = 253;
new_img.style.width = 486;
new_img.style.border = 0;

img_col.appendChild(new_img);
if(target_row.firstChild){
target_row.removeChild(target_row.firstChild); //remove any prior image you set.
}
target_row.appendChild(img_col);


Or better yet, just hard code the collumn and image in the html and give it an id attribute. then just swap out the image src.

The-Ensemble
07-27-2006, 11:36 AM
Hi sorry whats DOM?

Code Monkey
07-27-2006, 01:31 PM
Document Object Model. It's they way you should be writing to the browser screen.

The-Ensemble
07-27-2006, 07:49 PM
Ok. so do i replace my script with that or what?
Sorry if i appear really stupid im new at this.