задание - написать конвертер валют. нашёл xml от госбанка с курсом. проблема в том что не знаю как связать документы таким образом чтобы функция получала курс из xml.
<!-- vhod -->
<SCRIPT LANGUAGE="JavaScript">
function roundToPennies(n)
{
pennies = n * 100;
pennies = Math.round(pennies);
strPennies = "" + pennies;
len = strPennies.length;
first = strPennies.substring(0, len - 2) + ".";
last = strPennies.substring(len - 2, len);
if(first == ".")
{
first = "0."
}
if(last.length == 1)
{
last += "0";
}
return first + last;
}
//LEI
function ComputeMDL()
{
MDL_countValue = document.forms['MoneyForm'].elements['MDL_box'].value;
curs_USDValue = document.forms['MoneyForm'].elements['USD_curs'].value;
curs_EURValue = document.forms['MoneyForm'].elements['EUR_curs'].value;
{
Money = eval(MDL_countValue);
{
cU = eval(curs_USDValue);
cE = eval(curs_EURValue);
count_USD = Money / cU;
count_EUR = Money / cE;
document.forms['0'].elements['USD_box'].value = roundToPennies(count_USD);
document.forms['0'].elements['EUR_box'].value = roundToPennies(count_EUR);
}
}
}
//DOLLAR
function ComputeUSD()//-->
{
USD_countValue = document.forms['MoneyForm'].elements['USD_box'].value;
curs_USDValue = document.forms['MoneyForm'].elements['USD_curs1'].value;
curs_EURValue = document.forms['MoneyForm'].elements['EUR_curs1'].value;
{
Money = eval(USD_countValue);
{
cD = eval(curs_USDValue);
cE = eval(curs_EURValue);
count_MDL = Money * cD;
count_EUR = count_MDL / cE;
document.forms['0'].elements['MDL_box'].value = roundToPennies(count_MDL);
document.forms['0'].elements['EUR_box'].value = roundToPennies(count_EUR);
}
}
}
//EURO
function ComputeEUR()//-->
{
EUR_countValue = document.forms['MoneyForm'].elements['EUR_box'].value;
curs_USDValue = document.forms['MoneyForm'].elements['USD_curs2'].value;
curs_EURValue = document.forms['MoneyForm'].elements['EUR_curs2'].value;
{
Money = eval(EUR_countValue);
{
cD = eval(curs_USDValue);
cE = eval(curs_EURValue);
count_MDL = Money * cE;
count_USD = count_MDL / cD;
document.forms['0'].elements['MDL_box'].value = roundToPennies(count_MDL);
document.forms['0'].elements['USD_box'].value = roundToPennies(count_USD);
}
}
}
function clean_fields()//-->
{
document.forms['0'].elements['MDL_box'].value = '';
document.forms['0'].elements['USD_box'].value = '';
document.forms['0'].elements['EUR_box'].value = '';
}
// -->
</SCRIPT>
<CENTER>
<H1> </H1>
<H1> </H1>
<FORM NAME="MoneyForm">
<p> </p>
<h1>Convertor valutar</h1>
<table width="270" height="158" border="0">
<tr>
<td width="33%" height="62"><div align="center"><img src="flaags/flag_md_big.gif" width="103" height="58" /></div></td>
<td width="67%"><input name="MDL_box" type="text" onClick="clean_fields()" onKeyUp="ComputeMDL()" size="20" />
<input type="hidden" name="EUR_curs" value="16.50" />
<input type="hidden" name="USD_curs" value="12.40" /></td>
</tr>
<tr>
<td height="62"><div align="center"><img src="flaags/us-lgflag.gif" width="103" height="58" /></div></td>
<td><input type="Text" name="USD_box" size="20" onkeyup="ComputeUSD()" onClick="clean_fields()" />
<input type="hidden" name="EUR_curs1" value="16.50" />
<input type="hidden" name="USD_curs1" value="12.40" /> </td>
</tr>
<tr>
<td height="60"><div align="center"><img src="flaags/EU.jpg" width="103" height="58" /></div></td>
<td><input type="text" name="EUR_box" size="20" onKeyUp="ComputeEUR()" onClick="clean_fields()" />
<input type="hidden" name="EUR_curs2" value="16.50" />
<input type="hidden" name="USD_curs2" value="12.40" /></td>
</tr>
</table>
</FORM>
</CENTER>