• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 222
  • Last Modified:

How do i get javscript to interpret my entity names corrctly

I have a variable in one of my scripts which adds a currency sign to the beginning of whatever amount is calculated. The variable looks like this when using pounds sterling:

var currency = "£";

The problem is that using a regular £ sign does not work and a small square appears in its place. I have tried using an entity name like this:

var currency = "£"; but instead of a pound sign the script reproduces the entity name verbatim. This is also the case if I use an entity number.

Is there a way of using an entity name but having it reproduced on the page as the symbol it stands for?
0
grigorovsky
Asked:
grigorovsky
1 Solution
 
Michel PlungjanIT ExpertCommented:
Depending on the codepage of your site the currency symbol should work. Please show the code you have now since entities ALSO should work
0
 
grigorovskyAuthor Commented:
Not sure which code you're referring to. The document type statement is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Open in new window


The javascript code (with currency statement in bold) is:

<!-- Begin
var max_units = 10; // quantities in excess of max_units all have the same unit price
[b]var currency = "&pound;"; // currency sign used in 'formatMessage()'//[/b]
Edit this function to reflect your discount prices! 
function getDiscountPrice(units) {
// Note: It is important to work your way down from max to min amounts!
if (units >= max_units) return 0.00;
if (units == 9) return 0.00;
if (units == 8) return 0.00;
if (units == 7) return 0.00;
if (units == 6) return 0.00;
if (units == 5) return 28.00;
if (units == 4) return 30.00;
if (units == 3) return 32.00;
if (units == 2) return 32.50;
if (units == 1) return 35.00;
if (units <= 0) return 0.00;
}
function getNumberOfUnits() {
var units = document.ents_Signup.units.value; 
return (units == "") ? 0 : units;
}
function showResult(result) {
// adjust the following line if result must popup somewhere else
document.ents_Signup.respons.value = result;
document.ents_Signup.amount.value = result2;
}
function formatMessage(units, unit_price) {
return " @ " + currency + formatPrice(unit_price);
}
function formatMessagee(units, unit_price) {
return formatPrice(units * unit_price);
}
// AltUnits (alternate units): add extra units to reach minimum for next discount price
function getAltUnits(units) {
var discount_price = getDiscountPrice(units);
if (units > max_units) do { units++ } while (discount_price == getDiscountPrice(units));
return units;
}
function findPrice() {
var units = getNumberOfUnits();
var unit_price = getDiscountPrice(units);
var alt_units = getAltUnits(units);
var alt_unit_price = getDiscountPrice(alt_units);
var result;
if ((units * unit_price) < (alt_units * alt_unit_price)) 
result = formatMessage(units, unit_price);
else
result = formatMessage(alt_units, alt_unit_price);
if ((units * unit_price) < (alt_units * alt_unit_price)) 
result2 = formatMessagee(units, unit_price); 
else
result2 = formatMessagee(alt_units, alt_unit_price);
showResult(result);
}
function formatPrice(value) {
var result= Math.floor(value) + ".";
var cents = 100 * (value-Math.floor(value)) + 0.5;
result += Math.floor(cents / 10);
result += Math.floor(cents % 10);
return result;
}
function filterNonNumeric(field) {
var result = new String();
var numbers = "012345";
var chars = field.value.split(""); // create array 
for (i = 0; i < chars.length; i++) {
if (numbers.indexOf(chars[i]) != -1) result += chars[i];
}
if (field.value != result) field.value = result;
}
//  End -->

Open in new window

0
 
Roman GhermanCommented:
Hi,
This can also happen because that you file were you put pound sign is saved using an wrong encoding.
Try to save the file using a different encoding, using notepad or a similar application.

I also had an issue like that in the past, and when I changed the encoding everything went OK.
Unfortunately I can't remember what encoding I have used.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
grigorovskyAuthor Commented:
The thing is that I use the entity name "&pound;" elsewhere in the same document and it renders perfectly. It is just the javascript rendering that is not working!
0
 
Michel PlungjanIT ExpertCommented:
try

var currency = "\u00A3";

and I think when you use the pound sign, you had saved you document in another codepage than utf8 - then it does not matter you have the meta tag. the file must be saved as utf8 to be show as such too
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now