habib
09-18-2002, 04:38 PM
Hi,
I have created some functions in an external.js file. I now want to use them in my htm files to display prices in various currencies. I used the following syntax to call the function:
<script language ="Javascript" src="amount.js">
document.write(convert_amount(10));
</script>
but it didn't display any amount.
The code for amount.js is as follows:
function getCookie(name){
var cname = name + "=";
var dc = document.cookie;
if (dc.length > 0) {
begin = dc.indexOf(cname);
if (begin != -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin, end));
}
}
return null;
}
function convert_amount (amount) {
var input_amount = amount;
var sa_rate = 15;
var us_rate = 1.4;
var eu_rate = 1.6;
if (getCookie('home_location') == 'UK') {
return '£'+(input_amount); }
else
if (getCookie('home_location') == 'SA') {
return 'R'+(input_amount * sa_rate); }
else
if (getCookie('home_location') == 'US') {
return '$'+(input_amount * us_rate); }
else
if (getCookie('home_location') == 'EU') {
return 'E'+(input_amount * eu_rate); }
}
But when I copied the function from amount.js and pasted it into the <head> of the htm file and then use the following syntax:
<script language ="Javascript">
document.write(convert_amount(10));
</script>
it works like a dream!! I get the price '10' in GBP, when I change the country of residence it displays the price accordingly:
Europe = Euros
South Africa = SA Rands
United Kingdom = GBP
United States = USD
I want to use the function on lots of htm files where the 'amount_value' will keep on changing. How do I get it to work???
Is there some syntax I have to have in the external file that might be missing?
:confused:
I have created some functions in an external.js file. I now want to use them in my htm files to display prices in various currencies. I used the following syntax to call the function:
<script language ="Javascript" src="amount.js">
document.write(convert_amount(10));
</script>
but it didn't display any amount.
The code for amount.js is as follows:
function getCookie(name){
var cname = name + "=";
var dc = document.cookie;
if (dc.length > 0) {
begin = dc.indexOf(cname);
if (begin != -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin, end));
}
}
return null;
}
function convert_amount (amount) {
var input_amount = amount;
var sa_rate = 15;
var us_rate = 1.4;
var eu_rate = 1.6;
if (getCookie('home_location') == 'UK') {
return '£'+(input_amount); }
else
if (getCookie('home_location') == 'SA') {
return 'R'+(input_amount * sa_rate); }
else
if (getCookie('home_location') == 'US') {
return '$'+(input_amount * us_rate); }
else
if (getCookie('home_location') == 'EU') {
return 'E'+(input_amount * eu_rate); }
}
But when I copied the function from amount.js and pasted it into the <head> of the htm file and then use the following syntax:
<script language ="Javascript">
document.write(convert_amount(10));
</script>
it works like a dream!! I get the price '10' in GBP, when I change the country of residence it displays the price accordingly:
Europe = Euros
South Africa = SA Rands
United Kingdom = GBP
United States = USD
I want to use the function on lots of htm files where the 'amount_value' will keep on changing. How do I get it to work???
Is there some syntax I have to have in the external file that might be missing?
:confused: