Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript_howto thread: Re: onload and Netscape 4.78


Message #1 by "Rabita Yusoff" <yusoffr@y...> on Wed, 25 Sep 2002 10:26:38
Hi Garrett,

I don't have the answer to your question. Just want to thank you that 
your script really helps me a lot. I reuse your codes to add dynamic 
cells generated from XML. I'd like to share the script here:

Thanks again.
Rabita


************************************************************************

<script language="JavaScript" type="text/javascript">


var num_elements = window.document.frmForms.elements.length;
var rowTotal = 0
var cellIndex = 0

var elems = window.document.frmForms.elements;
var numOfCols = new Number(document.all.hidColNum.value) + 1;
var numOfRows = elems.length / numOfCols;
var posTotal = numOfCols - 1



function addItAll(){
		 addTheFields()
		 update()
	}


function addTheFields() {

	tableTotal = 0;
		
	for (row = 0; row < numOfRows; row++) {
		rowTotal = 0;
		for (col = 0; col < numOfCols; col++) {
			cellIndex = (row*numOfCols+col);

			if (col == posTotal) {
				col2 = 1;
				document.frmForms.elements
[cellIndex].value = 0;
				for (col2 = 1; col2 < posTotal; col2++) {
					document.frmForms.elements
[cellIndex].value =  new 

Number(document.frmForms.elements[cellIndex].value) + new Number
(document.frmForms.elements[cellIndex-col2].value);
				}
				rowTotal = rowTotal + new Number (getVal
(document.frmForms.elements[cellIndex]));

					}
			
			
		}
		tableTotal = tableTotal + rowTotal;
	}
//alert(posTotal)
	
}



function getVal(elem) {
    if ((elem.value == "") || (elem.value == null) || (elem.value == " "))
        return 0;
    else
        return elem.value;

}


function update() {
		rowArr = new Array();

		for (i=0; i<numOfCols; i++) {
			rowVal = 0;

			for (j=0; j<(numOfRows); j++) {
				pos = (numOfCols * j) + i
				if (elems[pos].value == null)
					elems[pos].value = 0;
				val = new Number(elems[pos].value);

				rowVal = rowVal + val;
			}

			rowArr[rowArr.length] = rowVal;
		}

		<!--for (a=0; a<rowArr.length; a++) -->
		<!--	alert("This is the number " +rowArr[a]);-->
	
	}

</script>

****************************************************************
> I have a JavaScript that adds several cells up using the DOM tree on a 
page,
> the problem is that the client wants ot use Netscape 4.78.  This page 
works
> great on Netscape 6 and IE all versions but not in Netscape 4.78, it 
simply
> does not run. Please help.
> 
> Note: JavaScript on the bottom.
> 
> Any help greatly need, thanks so much.
> Garrett
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> 
> <html>
> <head>
> 	<title>Tester</title>
> </head>
> 
> <body bgcolor="#FFFFFF" text="#000000"  topmargin="0" marginheight="0"
> onLoad='addItAll();' link="#000000" vlink="#000000" alink="#000000">
>   <Form name="form1" method="get" >
>                 <table width="100%" border="0" cellspacing="0"
> cellpadding="0" name="table01_back" summary="data">
>                   <tr>
>                     <td width="2%">&nbsp; </td>
>                     <td width="98%" bgcolor="#386427">
>                       <table width="100%" border="0" cellspacing="1"
> cellpadding="2" summary="data">
>                         <tr ID="T3R1" >
>                           <td ID="T3R1C1" colspan="12"
> class="chartTop"><span class="chartTopbold">Set
>                             Mission</span><br>
> 							</td>
> 						  </tr>
>                         <tr ID="T3R2" >
>                           <td ID="T3R2C1" 
class="yelloChartbold">&nbsp;</td>
>                           <td ID="T3R2C2" colspan="3"
> class="yelloChartbold">NPS
>                             Trainers</td>
>                           <td ID="T3R2C3" colspan="3"
> class="yelloChartbold">NPS
>                             Non-Trainers</td>
>                           <td ID="T3R2C4" colspan="3"
> class="yelloChartbold">Prior
>                             Service</td>
>                           <td ID="T3R2C5" colspan="2" 
class="yelloChartbold"
> width="20%">Total</td>
>                         </tr>
>                         <tr ID="T3R3" class="yellowChart">
>                           <td ID="T3R3C1">&nbsp;</td>
>                           <td ID="T3R3C2">NPSM</td>
>                           <td ID="T3R3C3">NPSF</td>
>                           <td ID="T3R3C4">Total</td>
>                           <td ID="T3R3C5">NPSM</td>
>                           <td ID="T3R3C6">NPSF</td>
>                           <td ID="T3R3C7">Total</td>
>                           <td ID="T3R3C8">PS T</td>
>                           <td ID="T3R3C9">PS NT</td>
>                           <td ID="T3R3C10">Total</td>
>                           <td ID="T3R3C11" colspan="2"><input 
type="text"
> name="textfield1" size="5" onblur='addItAll();'></td>
>                         </tr>
>                         <tr ID="T3R4" class="yellowChart">
>                           <td ID="T3R4C1">Quarter 1</td>
>                           <td ID="T3R4C2"><input type="text"
> name="textfield1" size="5" value="7762"  onblur='addItAll();'></td>
>                           <td ID="T3R4C3"><input type="text"
> name="textfield2" size="5" value="2838"  onblur='addItAll();'></td>
>                           <td ID="T3R4C4"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R4C5"><input type="text"
> name="textfield54" size="5" value="546"  onblur='addItAll();'></td>
>                           <td ID="T3R4C6"><input type="text"
> name="textfield55" size="5" value="154"  onblur='addItAll();'></td>
>                           <td ID="T3R4C7"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R4C8"><input type="text"
> name="textfield562" size="5" value="414"  onblur='addItAll();'></td>
>                           <td ID="T3R4C9"><input type="text"
> name="textfield5622" size="5" value="986"  onblur='addItAll();'></td>
>                           <td ID="T3R4C10"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R4C11" colspan="2"><input 
type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                         </tr>
>                         <tr ID="T3R5" class="yellowChart">
>                           <td ID="T3R5C1">Quarter 2</td>
>                           <td ID="T3R5C2"><input type="text"
> name="textfield5626" size="5" value="14947"  onblur='addItAll();'></td>
>                           <td ID="T3R5C3"><input type="text"
> name="textfield5626" size="5" value="4453"  onblur='addItAll();'></td>
>                           <td ID="T3R5C4"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R5C5"><input type="text"
> name="textfield5628" size="5" value="702"  onblur='addItAll();'></td>
>                           <td ID="T3R5C6"><input type="text"
> name="textfield5629" size="5" value="198"  onblur='addItAll();'></td>
>                           <td ID="T3R5C7"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R5C8"><input type="text"
> name="textfield56211" size="5" value="630"  onblur='addItAll();'></td>
>                           <td ID="T3R5C9"><input type="text"
> name="textfield56212" size="5" value="970"  onblur='addItAll();'></td>
>                           <td ID="T3R5C10"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R5C11" colspan="2"><input 
type="text"
> name="textfield2" size="5"  onblur='addItAll();'></td>
>                         </tr>
>                         <tr ID="T3R6" class="yellowChart">
>                           <td ID="T3R6C1">Quarter 3</td>
>                           <td ID="T3R6C2"><input type="text"
> name="textfield562162" size="5" value="13720"  onblur='addItAll
();'></td>
>                           <td ID="T3R6C3"><input type="text"
> name="textfield56216" size="5" value="2980"  onblur='addItAll();'></td>
>                           <td ID="T3R6C4"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R6C5"><input type="text"
> name="textfield56218" size="5" value="624"  onblur='addItAll();'></td>
>                           <td ID="T3R66"><input type="text"
> name="textfield56219" size="5" value="176"  onblur='addItAll();'></td>
>                           <td ID="T3R6C7"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R6C8"><input type="text"
> name="textfield56221" size="5" value="615"  onblur='addItAll();'></td>
>                           <td ID="T3R6C9"><input type="text"
> name="textfield56222" size="5" value="885"  onblur='addItAll();'></td>
>                           <td ID="T3R6C10"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R6C11" colspan="2"><input 
type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                         </tr>
>                         <tr ID="T3R7" class="yellowChart">
>                           <td ID="T3R7C1">Quarter 4</td>
>                           <td ID="T3R7C2"><input type="text"
> name="textfield56225" size="5" value="18550"  onblur='addItAll();'></td>
>                           <td ID="T3R7C3"><input type="text"
> name="textfield56226" size="5" value="4700"  onblur='addItAll();'></td>
>                           <td ID="T3R7C4"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R7C5"><input type="text"
> name="textfield562292" size="5" value="468"  onblur='addItAll();'></td>
>                           <td ID="T3R7C6"><input type="text"
> name="textfield56229" size="5" value="132"  onblur='addItAll();'></td>
>                           <td ID="T3R7C7"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R7C8"><input type="text"
> name="textfield56231" size="5" value="290"  onblur='addItAll();'></td>
>                           <td ID="T3R7C9"><input type="text"
> name="textfield56232" size="5" value="1210"  onblur='addItAll();'></td>
>                           <td ID="T3R7C10"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R7C11" colspan="2"><input 
type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                         </tr>
> 						<tr ID="T3R8" 
class="yellowChart">
>                           <td ID="T3R8C1">Total Row</td>
>                           <td ID="T3R8C2"><input type="text"
> name="textfield56225" size="5"  onblur='addItAll();'></td>
>                           <td ID="T3R8C3"><input type="text"
> name="textfield56226" size="5"  onblur='addItAll();'></td>
>                           <td ID="T3R8C4"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R8C5"><input type="text"
> name="textfield562292" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R8C6"><input type="text"
> name="textfield56229" size="5"  onblur='addItAll();'></td>
>                           <td ID="T3R8C7"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R8C8"><input type="text"
> name="textfield56231" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R8C9"><input type="text"
> name="textfield56232" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R8C10"><input type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                           <td ID="T3R8C11" colspan="2"><input 
type="text"
> name="textfield2" size="5" onblur='addItAll();'></td>
>                         </tr>
>                         <tr ID="T3R9" align="right" class="chartBottom">
>                           <td ID="T3R9C1" colspan="12"><a
> href="Armygroup_accession_a_v.html"
> onMouseUp="MM_swapImage
('Submit','','../../../../games/USAREC/media/submit_h
> it.gif',1)"
> onMouseOver="MM_swapImage
('Submit','','../../../../games/USAREC/media/submit
> _on.gif',1)"><img name="Submit" border="0"
> src="../../../../games/USAREC/media/submit.gif" width="100" height="22"
> alt="submit button"></a></td>
>                         </tr>
>                       </table>
>                     </td>
>                   </tr>
>                 </table>
>               </td>
>             </tr>
>           </table>
>         </td>
>       </tr>
>     </table>
>   </Form>
> 
> </body>
> <script language="JavaScript" type="text/javascript">
> 
> var num_elements = window.document.form1.elements.length;
> var rowTotal = 0
> var cellIndex = 0
> 
> function addItAll(){
> 		 addTheFields()
> 		 update()
> 	}
> function addTheFields() {
> 
> 	tableTotal = 0;
> 	for (row = 0; row < 4; row++) {
> 		rowTotal = 0;
> 		for (col = 0; col < 10; col++) {
> 			cellIndex = (row*10+col+1);
> 
> 
> 			if (col == 9) {
> 			   document.form1.elements[cellIndex].value = 
rowTotal;
> 
> 			   	}
> 			else {
> 				 if ((col == 2) || (col == 5)||(col == 8))
{
> 				 	document.form1.elements
[cellIndex].value =  new
> Number(document.form1.elements[cellIndex-1].value) + new
> Number(document.form1.elements[cellIndex-2].value);
> 					rowTotal = rowTotal + new Number
> (getVal(document.form1.elements[cellIndex]));
> 					}
> 			}
> 		}
> 		tableTotal = tableTotal + rowTotal;
> 	}
>        document.form1.elements[0].value = tableTotal;
> }
> 
> function getVal(elem) {
>     if ((elem.value == "") || (elem.value == null) || (elem.value 
== " "))
>         return 0;
>     else
>         return elem.value;
> 
> }
> 
> 
> 
> var elems = window.document.form1.elements;
> var numOfCols = 10;
> 
> 	function update() {
> 		rowArr = new Array();
> 
> 		numOfRows = elems.length / numOfCols;
> 		for (i=0; i<numOfCols; i++) {
> 			rowVal = 0;
> 
> 			for (j=0; j<(numOfRows -2); j++) {
> 				pos = (numOfCols * j) + i
> 				if (elems[pos].value == null)
> 					elems[pos].value = 0;
> 				val = new Number(elems[pos].value);
> 
> 				rowVal = rowVal + val;
> 			}
> 
> 			rowArr[rowArr.length] = rowVal;
> 		}
> 
> 		<!--for (a=0; a<rowArr.length; a++) -->
> 		<!--	alert("This is the number " +rowArr[a]);-->
> 
> 	window.document.form1.elements[41].value = rowArr[1];
> 	window.document.form1.elements[42].value = rowArr[2];
> 	window.document.form1.elements[43].value = rowArr[3];
> 	window.document.form1.elements[44].value = rowArr[4];
> 	window.document.form1.elements[45].value = rowArr[5];
> 	window.document.form1.elements[46].value = rowArr[6];
> 	window.document.form1.elements[47].value = rowArr[7];
> 	window.document.form1.elements[48].value = rowArr[8];
> 	window.document.form1.elements[49].value = rowArr[9];
> 	window.document.form1.elements[50].value =
> window.document.form1.elements[0].value;
> 	}
> </script>
> 
> </html>
> 

  Return to Index