PhotoJoe47
10-21-2005, 11:08 AM
Hi you all,
I have some javascript that I have written into the <body> section and it works great. But I would like to make it into a javascript function and define the function in the <head> section. Then in the <body> section write a small bit of javascript that would call the function() object.
Here is section of the code from the htm file as it is now and works as intented.
<div align="center">
<center>
<table border="0" cellpadding="5" cellspacing="0" width="90%">
<SCRIPT LANGUAGE="JavaScript">
var SizeH = '0'; // for height of tumbnail image
var SizeW = '0';// for width of tumbnail image
var nR = '4'; // for number of rows in table
var nC = '5'; // for number of cells per row in table
var nS = '0'; // for count of slides used in table to index an array of image.src
for(row=0; row<=nR-1; row++)
{
document.write("<tr>");
for(cell=0; cell<=nC-1; cell++)
{
nS = cell + (row * nC)
if(arrSize[cell + (nS)] == true)
{
SizeH = '67';
SizeW = '100';
}
else{
SizeH = '100';
SizeW = '67';
}
document.write("<td width='20%' height='116' valign='middle' align='center'>");
document.write('<a href="javascript:winopen(\'../single_Slide.htm\', "' + arrSlidePaths[nS] + '")">');
document.write("<img border='1' src='images/Other/blank.gif' alt = 'Click here'");
document.write("width=" + SizeW + "height=" + SizeH + "></a></td>");
}
document.write("</tr>");
document.write("<tr>");
for(cell=0; cell<=nC-1; cell++)
{
nS = cell + (row * nC)
document.write("<td width='20%' height='20' valign='bottom' align='center'><font face='Comic Sans MS' size='4' color='#CC3300'>" + arrSlideNumbers[nS] + "</font></td>");
}
document.write("</tr>");
}
</script>
</table>
</center>
Now I think if I put all of the above code that is between the <script></script> tags inside a pair of {} brackets and then add this bit of code before the { opening bracket.
function writeCells(NumR, NumC)
Then change:
var nR = '4';
var nc = '5':
to:
var nr = NumR;
var nc = NumC;
I will have correctly define the function, right? And I can move this to the <head> section?
Now in the <body> section I should be able to insert this where I want the rows and cells of the table create.
<div align="center">
<center>
<table border="0" cellpadding="5" cellspacing="0" width="90%">
<SCRIPT LANGUAGE="JavaScript">
writeCells('4', '5');
</script>
</table>
</center>
</div>
Is this correct?
I don't know what I'm doing wrong, but I can't seem to get this to work.
PhotoJoe
I have some javascript that I have written into the <body> section and it works great. But I would like to make it into a javascript function and define the function in the <head> section. Then in the <body> section write a small bit of javascript that would call the function() object.
Here is section of the code from the htm file as it is now and works as intented.
<div align="center">
<center>
<table border="0" cellpadding="5" cellspacing="0" width="90%">
<SCRIPT LANGUAGE="JavaScript">
var SizeH = '0'; // for height of tumbnail image
var SizeW = '0';// for width of tumbnail image
var nR = '4'; // for number of rows in table
var nC = '5'; // for number of cells per row in table
var nS = '0'; // for count of slides used in table to index an array of image.src
for(row=0; row<=nR-1; row++)
{
document.write("<tr>");
for(cell=0; cell<=nC-1; cell++)
{
nS = cell + (row * nC)
if(arrSize[cell + (nS)] == true)
{
SizeH = '67';
SizeW = '100';
}
else{
SizeH = '100';
SizeW = '67';
}
document.write("<td width='20%' height='116' valign='middle' align='center'>");
document.write('<a href="javascript:winopen(\'../single_Slide.htm\', "' + arrSlidePaths[nS] + '")">');
document.write("<img border='1' src='images/Other/blank.gif' alt = 'Click here'");
document.write("width=" + SizeW + "height=" + SizeH + "></a></td>");
}
document.write("</tr>");
document.write("<tr>");
for(cell=0; cell<=nC-1; cell++)
{
nS = cell + (row * nC)
document.write("<td width='20%' height='20' valign='bottom' align='center'><font face='Comic Sans MS' size='4' color='#CC3300'>" + arrSlideNumbers[nS] + "</font></td>");
}
document.write("</tr>");
}
</script>
</table>
</center>
Now I think if I put all of the above code that is between the <script></script> tags inside a pair of {} brackets and then add this bit of code before the { opening bracket.
function writeCells(NumR, NumC)
Then change:
var nR = '4';
var nc = '5':
to:
var nr = NumR;
var nc = NumC;
I will have correctly define the function, right? And I can move this to the <head> section?
Now in the <body> section I should be able to insert this where I want the rows and cells of the table create.
<div align="center">
<center>
<table border="0" cellpadding="5" cellspacing="0" width="90%">
<SCRIPT LANGUAGE="JavaScript">
writeCells('4', '5');
</script>
</table>
</center>
</div>
Is this correct?
I don't know what I'm doing wrong, but I can't seem to get this to work.
PhotoJoe