Forum Moderators: open

Message Too Old, No Replies

using array with Dom Structure ?

is this possible?

         

nanat

6:24 am on Jul 10, 2009 (gmt 0)

10+ Year Member



Is this Possible? i know some basic arrays in php but Dom Structure this is insane because i don't now how to handle it and im just a begginer of Dom Structure :((..
imaging you have 100 table with out arrays.. T_T


<html>
<head>
<script type="text/javascript">
function upperCase(n)
{
var A = document.getElementById('cost'+n).value;
var B = document.getElementById('pd1'+n).value;
var C = document.getElementById('pd2'+n).value;
var D = document.getElementById('pd3'+n).value;
var E = document.getElementById('pd4'+n).value;
var F = document.getElementById('pd5'+n).value;

document.getElementById('resultpd1'+n).value = A*B;
document.getElementById('resultpd2'+n).value = A*C;
document.getElementById('resultpd3'+n).value = A*D;
document.getElementById('resultpd4'+n).value = A*E;
document.getElementById('resultpd5'+n).value = A*F;

document.getElementById('total').value
= parseFloat( document.getElementById('resultpd1').value )
+ parseFloat( document.getElementById('resultpd2').value )
+ parseFloat( document.getElementById('resultpd3').value )
+ parseFloat( document.getElementById('resultpd4').value )
+ parseFloat( document.getElementById('resultpd5').value );
}
</script>
</head>
<body>
Cost: <input type="text" id="cost" name="cost" onchange="upperCase(1)"/>
<br />
PD1: <input type="text" id="pd1" name="pd1" onchange="upperCase(1)" />
<input type="text" id="resultpd1" name="resultpd1" readonly="readonly"/>
<br />
PD2: <input type="text" id="pd2" name="pd2" onchange="upperCase(1)" />
<input type="text" id="resultpd2" name="resultpd2" readonly="readonly"/>
<br />
PD3: <input type="text" id="pd3" name="pd3" onchange="upperCase(1)" />
<input type="text" id="resultpd3" name="resultpd3" readonly="readonly"/>
<br />
PD4: <input type="text" id="pd4" name="pd4" onchange="upperCase(1)" />
<input type="text" id="resultpd4" name="resultpd4" readonly="readonly"/>
<br />
PD5: <input type="text" id="pd5" name="pd5" onchange="upperCase(1)" />
<input type="text" id="resultpd5" name="resultpd5" readonly="readonly"/>
<br />
<br />
<input type="text" id="total" name="total" readonly="readonly"/>

</body>
</html>

Gracias ^^

daveVk

7:17 am on Jul 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<html>
<head>
<script type="text/javascript">
function upperCase()
{
var tot = 0;
var el,val;
var i=1;
var cost = document.getElementById('cost').value;
while ( (el=document.getElementById('resultpd'+ i))!==null ) {
val = cost * document.getElementById('pd'+i).value;
el.value = val;
tot += val;
i++;
}
document.getElementById('total').value = tot;
}
</script>
</head>
<body>
Cost: <input type="text" id="cost" name="cost" onchange="upperCase()"/>
<br />
PD1: <input type="text" id="pd1" name="pd1" onchange="upperCase()" />
<input type="text" id="resultpd1" name="resultpd1" readonly="readonly"/>
<br />
PD2: <input type="text" id="pd2" name="pd2" onchange="upperCase()" />
<input type="text" id="resultpd2" name="resultpd2" readonly="readonly"/>
<br />
PD3: <input type="text" id="pd3" name="pd3" onchange="upperCase(1)" />
<input type="text" id="resultpd3" name="resultpd3" readonly="readonly"/>
<br />
PD4: <input type="text" id="pd4" name="pd4" onchange="upperCase()" />
<input type="text" id="resultpd4" name="resultpd4" readonly="readonly"/>
<br />
PD5: <input type="text" id="pd5" name="pd5" onchange="upperCase()" />
<input type="text" id="resultpd5" name="resultpd5" readonly="readonly"/>
<br />
<br />
<input type="text" id="total" name="total" readonly="readonly"/>

</body>
</html>

nanat

8:23 am on Jul 10, 2009 (gmt 0)

10+ Year Member



nice one dave.. u did it again..

thanks i tot this is impossible but u make it possible ^^

:bow: :bow: :bow:

nanat

9:25 am on Jul 10, 2009 (gmt 0)

10+ Year Member



last question plz.. ^^ how can i add all the pd?

var grace;
var mot = 0;

grace = parseFloat(document.getElementById('pd'+i).value) + tot;?

daveVk

10:58 am on Jul 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



function upperCase()
{
var tot = 0;
var mot = 0;
var el,val,pd;
var i=1;
var cost = document.getElementById('cost').value;
while ( (el=document.getElementById('resultpd'+ i))!==null ) {
pd = parseFloat(document.getElementById('pd'+i).value);
val = cost * pd;
el.value = val;
tot += val;
mot += pd;
i++;
}
document.getElementById('total').value = tot;
document.getElementById('mot').value = mot;
}

nanat

4:26 am on Jul 11, 2009 (gmt 0)

10+ Year Member



tnx bro.. simply best :D

nanat

4:26 am on Jul 11, 2009 (gmt 0)

10+ Year Member



tnx bro.. simply the best :D