PDA

View Full Version : I need help with my JavaScript



mhoque78
12-28-2004, 08:06 PM
Hi I need help with this javascript code. Once you are able to figure out please email me the Correct Code. My email address is "mhoque@isda.org"

It is just simple addition that will be needed to up into currency format for example:


Here is how it should add up with the currency format using commas and dollar sign. And it is not doing that.

$10,000.10
$10,000.11
$10,000.12
$10,000.13
-------------
$40,000.46



Here is my Code below: please help


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>test currency</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
</script>

<SCRIPT LANGUAGE="JavaScript">
function CollateralAssets()
{
var collreceivedUSD = document.submitform.collreceivedUSD.value
var collreceivedEUR = document.submitform.collreceivedEUR.value
var collreceivedGBP = document.submitform.collreceivedGBP.value
var collreceivedJPY = document.submitform.collreceivedJPY.value
document.submitform.TotalCollateralAssetsReceived. value=collreceivedUSD*1+collreceivedEUR*1+collrece ivedGBP*1+collreceivedJPY*1
}
</script>
</head>

<body>
<form name="submitform">
<table width="100%" border="1" bordercolor="#000033">
<tr valign="top" bgcolor="#000040">
<td width="16%"> <div align="center" class="style4"><strong><font size="2" face="Arial"><font color="#FFFFFF">Amount
received<br>
(USD)</font></font></strong></div></td>
</tr>
<tr>
<td bgcolor="#E9ECD9"><div align="center"> <font size="2" face="Arial">
<input name="collreceivedUSD" type="text" id="collreceivedUSD" value=".00" size="15" onBlur="CollateralAssets();this.value=formatCurrency(this. value);">
</font></div></td>
</tr>
<tr>
<td bgcolor="#E9ECD9"><div align="center"> <font size="2" face="Arial">
<input name="collreceivedEUR" type="text" id="collreceivedEUR" value=".00" size="15" onBlur="CollateralAssets();this.value=formatCurrency(this. value);">
</font></div></td>
</tr>
<tr>
<td bgcolor="#E9ECD9"><div align="center"> <font size="2" face="Arial">
<input name="collreceivedGBP" type="text" id="collreceivedGBP" value=".00" size="15" onBlur="CollateralAssets();this.value=formatCurrency(this. value);">
</font></div></td>
</tr>
<tr>
<td bgcolor="#E9ECD9"><div align="center"> <font size="2" face="Arial">
<input name="collreceivedJPY" type="text" id="collreceivedJPY" value=".00" size="15" onBlur="CollateralAssets();this.value=formatCurrency(this. value);">
</font></div></td>
</tr>
<tr>
<td bgcolor="#E9ECD9"><div align="center"></div></td>
</tr>
<tr>
<td bgcolor="#0000FF">
<div align="center"><font size="2" face="Arial">
<input name="TotalCollateralAssetsReceived" type="text" id="TotalCollateralAssetsReceived" onBlur="this.value=formatCurrency(this.value);" value=".00" size="15">
</font></div></td>
</tr>
</table>
</form>
</body>
</html>

cr3ative
12-28-2004, 08:23 PM
Naughty double poster. Please only post in one forum.

cr3ative