/    Sign up×
Community /Pin to ProfileBookmark

js working in firfox but not in ie and opera

I am not quite familiar with js, so need a lil help please.

I have a calculator that works in firefox but does not work in ie, and works for about 3 sec in opera.

Also, since the results are not displayed on page load, I need to add a button that will initiate the calculation – i need the code for this button please.

Here is the code of my script. Please leave out the non-english part.

[code]
<html>
<head>

<style>

td{border: 1px solid #EEEEEE; padding: 4px;}
table{border-collapse: collapse;}

#results td{border: 1px solid #777777;}
#results .label{width: 200px;}
#results .value{width: 50px;}

</style>

<script language=”javascript”>

var ids = {};

function gebi(n)
{
return document.getElementById(n);
}
function indexId(n)
{
ids[n] = gebi(n);
}

function init()
{
indexId(‘gains_sign’);
indexId(‘credit_sign’);
indexId(‘out_1_rate’);
indexId(‘out_2_rate’);
indexId(‘out_1_sum’);
indexId(‘out_2_gains’);
indexId(‘out_1_payment’);
indexId(‘out_2_payment’);
indexId(‘tracer’);

//indexId(‘gains_sign’);
}

function setCurrencySign(val)
{
var sign = (val == ‘rur’) ? ‘&#1088;&#1091;&#1073;.’ : ‘$’;
ids.gains_sign.innerHTML = sign;
ids.credit_sign.innerHTML = sign;
return true;
}

function getFormVal(frm,nam,floatval)
{
var val = frm.elements[nam].value;
if(val == ”)return 0;
if(!floatval)var numVal = parseInt(val);
else var numVal = parseFloat(val.replace(‘,’,’.’));
if(isNaN(numVal))alert(‘&#1074;&#1077;&#1076;&#1077;&#1085;&#1086; &#1085;&#1077; &#1095;&#1080;&#1089;&#1083;&#1086;&#1074;&#1086;&#1077; &#1079;&#1085;&#1072;&#1095;&#1077;&#1085;&#1080;&#1077; (‘+frm.elements[nam].value+’)!’);
return numVal;
}

function recalc(elm)
{
var f = elm.form;
var kurs = getFormVal(f,’kurs’);
var d = getFormVal(f,’gains’);
var s = getFormVal(f,’credit’);
var m = getFormVal(f,’period’)*12;
var p = getFormVal(f,’rate’,true);
var currency = f.elements[‘currency’].value;
var currSign = currency==”usd” ? ‘$’ : ‘&#1088;&#1091;&#1073;.’;

ids.tracer.value = d+’; ‘+s+’; ‘+m+’; ‘+p+’; ‘;

var koef1 = [0.4,0.475,0.55];
var koef2 = [0.7,0.75,0.8];
var res = [];

var sConv = (currency == ‘usd’) ? s : s/kurs;
var montPaym2 = sConv*(p/1200)/(1-(Math.pow((p/1200+1),-m)));
for(var i = 0; i < 3; i++)
{
var v1 = montPaym2/koef1[i];

var v2 = ((sConv*1.1*1.014/100/12)+334.04+montPaym2)/koef2[i];

res[i] = (v1 > v2) ? v1 : v2;
}

var res2 = [res[0],res[1],res[2]];

var out = -1;

if(res[0] <= 1000)out = res[0];
else if(res[1] > 1000 && res[1] <= 2500)out = res[1];
else if(res[2] > 2500)out = res[2];
else
{
out = Number.POSITIVE_INFINITY;
for(i = 0; i < 3; i++)
{
if(res[i] < out)out = res[i];
}
}

if(currency == ‘rur’)
{
out *= kurs;
montPaym2 *= kurs;
}

ids.out_2_payment.innerHTML = Math.ceil(montPaym2)+’ ‘+currSign;
ids.out_2_gains.innerHTML = Math.ceil(out)+’ ‘+currSign;

var dConv = (currency == ‘usd’) ? d : d/kurs;
var dd = 0.55;

var v1 = (dConv*dd*(1-Math.pow((1+p/1200),-(m-2))))/(p/1200);
var v2 = v1/(((1-Math.pow((1+p/1200),-(m-2))))/(p/1200));
var montPaym1 = v2;
var maxSum1 = montPaym1*(1-Math.pow((1+p/1200),-m))/(p/1200);

if(currency == ‘rur’)
{
maxSum1 *= kurs;
montPaym1 *= kurs;
}
ids.out_1_payment.innerHTML = Math.ceil(montPaym1)+’ ‘+currSign;
ids.out_1_sum.innerHTML = Math.ceil(maxSum1)+’ ‘+currSign;

ids.out_1_rate.innerHTML = ids.out_2_rate.innerHTML = p;
}

</script>

</head>
<body OnLoad=”init();”>

<form name=”main”>

<table width=”100&#37;” border=”0″ cellpadding=”0″ cellspacing=”0″>

<tr>
<td>&#1050;&#1091;&#1088;&#1089; &#1076;&#1086;&#1083;&#1083;&#1072;&#1088;&#1072;:</td>
<td><input type=”text” name=”kurs” value=”25″/>&nbsp;&nbsp;&#1088;&#1091;&#1073;.</td>
</tr>
<tr>
<td>&#1044;&#1086;&#1093;&#1086;&#1076;&#1099; &#1079;&#1072;&#1077;&#1084;&#1097;&#1080;&#1082;&#1086;&#1074; (&#1085;&#1072; &#1088;&#1091;&#1082;&#1080;):</td>
<td><input type=”text” name=”gains” onKeyUp=”recalc(this);” value=”10000″/>&nbsp;&nbsp;&#1088;&#1091;&#1073;.</td>
</tr>
<tr>
<td>&#1056;&#1072;&#1079;&#1084;&#1077;&#1088; &#1078;&#1077;&#1083;&#1072;&#1077;&#1084;&#1086;&#1075;&#1086; &#1082;&#1088;&#1077;&#1076;&#1080;&#1090;&#1072;:</td>
<td><input type=”text” name=”credit” onKeyUp=”recalc(this);” value=”200000″/>&nbsp;&nbsp;&#1088;&#1091;&#1073;.</td>
</tr>
<tr>
<td>&#1042;&#1072;&#1083;&#1102;&#1090;&#1072; &#1082;&#1088;&#1077;&#1076;&#1080;&#1090;&#1072;:</td>
<td>
<select name=”currency” onChange=”setCurrencySign(this.value); recalc(this);”>
<option value=”rur”>&#1088;&#1086;&#1089;&#1089;&#1080;&#1081;&#1089;&#1082;&#1080;&#1077; &#1088;&#1091;&#1073;&#1083;&#1080;</option>
<option value=”usd”>&#1076;&#1086;&#1083;&#1083;&#1072;&#1088; &#1057;&#1064;&#1040;</option>
</select> </td>
<td><span id=”credit_sign”></td>
</tr>
<tr>
<td>&#1057;&#1088;&#1086;&#1082; &#1082;&#1088;&#1077;&#1076;&#1080;&#1090;&#1072; (&#1083;&#1077;&#1090;):</td>
<td><input type=”text” name=”period” onKeyUp=”recalc(this);” value=”3″/>&nbsp;&nbsp;&#1083;&#1077;&#1090;</td>
</tr>
<tr>
<td>&#1055;&#1088;&#1086;&#1094;&#1077;&#1085;&#1090;&#1085;&#1072;&#1103; &#1089;&#1090;&#1072;&#1074;&#1082;&#1072;:</td>
<td><input type=”text” name=”rate” onKeyUp=”recalc(this);” value=”13.9″/>&nbsp;&nbsp;%</td>
</tr>
<tr>
<td colspan=”2″><div align=”center”>
<INPUT TYPE=”button” NAME=”myButton” VALUE=”&#1056;&#1072;&#1089;&#1089;&#1095;&#1080;&#1090;&#1072;&#1090;&#1100;” onKeyUp=”recalc(this)”>
</div></td>
</table>
</form>
<input type=”hidden” id=”tracer”>
<br>
<br>

<table width=”100%” border=”0″ cellpadding=”0″ cellspacing=”0″ id=”results”>
<tr>
<td colspan=”2″><b>&#1056;&#1072;&#1089;&#1095;&#1077;&#1090; &#1087;&#1086; &#1091;&#1082;&#1072;&#1079;&#1072;&#1085;&#1085;&#1086;&#1084;&#1091; &#1076;&#1086;&#1093;&#1086;&#1076;&#1091;<b></td>
<td colspan=”2″><b>&#1056;&#1072;&#1089;&#1095;&#1077;&#1090; &#1087;&#1086; &#1078;&#1077;&#1083;&#1072;&#1077;&#1084;&#1086;&#1084;&#1091; &#1082;&#1088;&#1077;&#1076;&#1080;&#1090;&#1091;<b></td>
</tr>
<tr>
<td>&#1055;&#1088;&#1086;&#1094;&#1077;&#1085;&#1090;&#1085;&#1072;&#1103; &#1089;&#1090;&#1072;&#1074;&#1082;&#1072;</td>
<td width=”70″ id=”out_1_rate”>&nbsp;%</td>
<td>&#1055;&#1088;&#1086;&#1094;&#1077;&#1085;&#1090;&#1085;&#1072;&#1103; &#1089;&#1090;&#1072;&#1074;&#1082;&#1072;</td>
<td width=”70″ id=”out_2_rate”>&nbsp;%</td>
</tr>
<tr>
<td>&#1052;&#1072;&#1082;&#1089;&#1080;&#1084;&#1072;&#1083;&#1100;&#1085;&#1072;&#1103; &#1089;&#1091;&#1084;&#1084;&#1072; &#1082;&#1088;&#1077;&#1076;&#1080;&#1090;&#1072;</td>
<td id=”out_1_sum”></td>
<td>&#1052;&#1080;&#1085;&#1080;&#1084;&#1072;&#1083;&#1100;&#1085;&#1099;&#1081; &#1076;&#1086;&#1093;&#1086;&#1076;</td>
<td id=”out_2_gains”></td>
</tr>
<tr>
<td>&#1045;&#1078;&#1077;&#1084;&#1077;&#1089;&#1103;&#1095;&#1085;&#1099;&#1081; &#1087;&#1083;&#1072;&#1090;&#1077;&#1078;</td>
<td id=”out_1_payment”></td>
<td>&#1045;&#1078;&#1077;&#1084;&#1077;&#1089;&#1103;&#1095;&#1085;&#1099;&#1081; &#1087;&#1083;&#1072;&#1090;&#1077;&#1078;</td>
<td id=”out_2_payment”></td>
</tr>
</table>

</body>
</html>
[/code]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@toicontienNov 13.2008 — How about:
[CODE]<INPUT TYPE="button" NAME="myButton" VALUE="..." [B]onclick="recalc(this);"[/B]> [/CODE]
Copy linkTweet thisAlerts:
@sainiashokauthorNov 14.2008 — This button part works, thanks.

Any idea about the other part? I get this error in IE on changing the drop-down.

Line45: error 'ids.gains_sign' - is null or not an object.

Line45: error 'ids.gains_sign' - is null or not an object.

Line161: error 'ids.gains_sign' - is null or not an object.

Line161: error 'ids.gains_sign' - is null or not an object.
Copy linkTweet thisAlerts:
@toicontienNov 14.2008 — In the HTML you posted, I don't see an tag whose Id is "gains_sign". I see "out_2_gains" though.
×

Success!

Help @sainiashok spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...