[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do i get javscript to interpret my entity names corrctly

Posted on 2011-03-13
7
Medium Priority
?
221 Views
Last Modified: 2012-05-11
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
Comment
Question by:grigorovsky
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 35122733
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
 

Author Comment

by:grigorovsky
ID: 35122886
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
 
LVL 9

Expert Comment

by:Roman Gherman
ID: 35123127
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:grigorovsky
ID: 35123170
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
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 35123518
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36123569
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question