|
|
vwphillips 06-24-2006, 08:47 PM see http://www.codingforums.com/showthread.php?t=89719
from PM
Hi Vic
You posted some code in response to a question from me re: calculating dynamic form fields.
Your code requires the user to click on a button to total the fields.
Can this be changed to calculate using onBlur?
thnx
tGirl
Yes
put an onblur event call to the function in the ip text boxes
Thought you were misleaded to follow the other somewhat dubious 'solution'
also see link below -and look for Form Compendium
torrentgirl 06-24-2006, 10:40 PM Great
thanks
Checking out your site now
torrentgirl 06-25-2006, 10:39 PM Vic
I added the onBlur and implemented your code into mine.
I don't get an error but it is not totalling.
I get a ZERO in the total field on the first onBlur
Here is one of my form fields:
<input name="<cfoutput>annualWrittenPremium#j#</cfoutput>" type="text" class="ip" onBlur="zxcCalculate('T1');" value="<cfoutput>#Evaluate("AnnualWrittenPremium" & j)#</cfoutput>" size="12" maxlength="12" />
NOTICE THAT THE NAME OF THE FIELD IS DYNAMICALLY CREATED WITH A LOOP/INDEX
Here is my total field (also dynamically created):
<input type="Text" name="<cfoutput>annualWPremPersonalAutoTOTAL#i#</cfoutput>" class="st" onBlur="zxcCalculate('T1');" size="12" value="<cfoutput>#Evaluate("annualWPremPersonalAutoTOTAL" & i)#</cfoutput>" maxlength="12" />
any suggestions?
added
vwphillips 06-26-2006, 08:57 AM <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<script type="text/javascript">
function zxcCalculate(zxcid){
var zxctable=document.getElementById(zxcid);
var zxcrows=zxctable.getElementsByTagName('TR');
var zxcstary=[];
var zxcgtotal=0;
var zxcgtotalip=null;
for (var zxc0=0;zxc0<zxcrows.length;zxc0++){
var zxcstotal=0;
var zxcstotalip=null;
var zxcips=zxcrows[zxc0].getElementsByTagName('INPUT');
for (var zxc1=0;zxc1<zxcips.length;zxc1++){
if (zxcips[zxc1].className.match('ip')){
if (zxcips[zxc1].value.length>0&&!isNaN(zxcips[zxc1].value)){
zxcstotal+=zxcips[zxc1].value*1;
}
}
if (zxcips[zxc1].className.match('st')){
zxcstary[zxc0]=zxcips[zxc1];
}
if (zxcips[zxc1].className.match('gt')){
zxcgtotalip=zxcips[zxc1];
}
}
if (zxcstary[zxc0]){ zxcstary[zxc0].value=zxcstotal; zxcgtotal+=zxcstotal; }
}
if (zxcgtotalip){ zxcgtotalip.value=zxcgtotal; }
}
</script>
<body >
<table id="T1"border="1">
<tr>
<td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');" ></td>
<td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');" ></td>
<td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');" ></td>
<td width="100" ><input class="st" type="text" size="4" onblur="zxcCalculate('T1');" ></td>
</tr>
<tr>
<td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');" ></td>
<td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');" ></td>
<td width="100" ><input class="ip" type="text" size="4" onblur="zxcCalculate('T1');" ></td>
<td width="100" ><input class="st" type="text" size="4" onblur="zxcCalculate('T1');" ></td>
</tr>
<tr>
<td width="100" ></td>
<td width="100" ></td>
<td width="100" ><input class="gt" type="text" size="4" ></td>
<td width="100" ><input type="button" value="Calculate" onclick="zxcCalculate('T1');" ></td>
</tr>
</table>
</body>
</html>
torrentgirl 06-26-2006, 05:52 PM that is what I have
it still does not calulate.
vwphillips 06-26-2006, 05:57 PM <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title></title>
</head>
<script type="text/javascript">
function zxcCalculate(zxcid){
var zxctable=document.getElementById(zxcid);
var zxcrows=zxctable.getElementsByTagName('TR');
var zxcstary=[];
var zxcgtotal=0;
var zxcgtotalip=null;
for (var zxc0=0;zxc0<zxcrows.length;zxc0++){
var zxcstotal=0;
var zxcstotalip=null;
var zxcips=zxcrows[zxc0].getElementsByTagName('INPUT');
for (var zxc1=0;zxc1<zxcips.length;zxc1++){
if (zxcips[zxc1].className.match('ip')){
if (zxcips[zxc1].value.length>0&&!isNaN(zxcips[zxc1].value)){
zxcstotal+=zxcips[zxc1].value*1;
}
}
if (zxcips[zxc1].className.match('st')){
zxcstary[zxc0]=zxcips[zxc1];
}
if (zxcips[zxc1].className.match('gt')){
zxcgtotalip=zxcips[zxc1];
}
}
if (zxcstary[zxc0]){ zxcstary[zxc0].value=zxcstotal; zxcgtotal+=zxcstotal; }
}
if (zxcgtotalip){ zxcgtotalip.value=zxcgtotal; }
}
</script>
<body >
<table id="T1"border="1">
<tr>
<td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');" ></td>
<td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');" ></td>
<td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');" ></td>
<td width="100" ><input class="st" type="text" size="4" onmouseout="zxcCalculate('T1');" ></td>
</tr>
<tr>
<td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');" ></td>
<td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');" ></td>
<td width="100" ><input class="ip" type="text" size="4" onmouseout="zxcCalculate('T1');" ></td>
<td width="100" ><input class="st" type="text" size="4" onmouseout="zxcCalculate('T1');" ></td>
</tr>
<tr>
<td width="100" ></td>
<td width="100" ></td>
<td width="100" ><input class="gt" type="text" size="4" ></td>
<td width="100" ><input type="button" value="Calculate" onclick="zxcCalculate('T1');" ></td>
</tr>
</table>
</body>
</html>
torrentgirl 06-27-2006, 04:31 AM Can someone please help me with this code that should calulate dynamic form fields?
I have an A.M.
I'm Desparate
vwphillips 06-27-2006, 05:05 PM each row is calulated individualy
your row have two inputs class="ip" which are calculated
but no input class='st'(sub total) to retain the result
all inputs class="st" are summed to produce the grand total.
without a class="st" in the row the sum of its inputs will not be included
you need an input class="st" in each row
make this type 'text' untill you are satisfied then make type 'hidden'
study and use the example I posted
torrentgirl 06-27-2006, 08:32 PM Ok thanks!! :thumbsup:
torrentgirl 06-27-2006, 08:39 PM So do I apply the class="st" to the actual <TR>?
Brandoe85 06-27-2006, 08:54 PM Use the example posted and go from their...
<td width="100" ><input class="st" type="text" size="4" onmouseout="zxcCalculate('T1');" ></td>
torrentgirl 06-28-2006, 01:05 AM :D
BUT
The code is on a loop and on the second loop it doesn't work.
Any suggestions?
|
|
|
|
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum
vBulletin® v3.8.2, Copyright ©2000-2013, Jelsoft Enterprises Ltd.