hi all

trying to set up an online shop BUT..

cant get javascript to accept "£" so having to use "$" instead..not good for a uk site lol

Dani AI

Generated

wanted the UK currency symbol to show up in JavaScript. correctly framed currency as data rather than a typed symbol, and pointed at character-encoding/display options. Practical fixes: keep amounts numeric and attach a currency code, ensure your files and responses are encoded correctly, and format the number for display only at the UI layer.

Save your HTML and .js files as UTF-8 (no BOM) and make sure the server sends a Content-Type header with the charset. If literal symbols still misrender, use the Unicode escape for the pound sign (\u00A3) in JS strings, or format with the platform formatter so you never build display strings by hand. Example using the browser API:

const price = 19.99;
const formatter = new Intl.NumberFormat('en-GB', { style: 'currency', currency: 'GBP' });
console.log(formatter.format(price)); // outputs '\u00A319.99'

const pound = '\u00A3';
console.log(pound + price);

Checklist if it still fails: confirm the HTTP charset in DevTools, verify your editor saved the files as UTF-8, ensure the page font contains the glyph, and keep the stored value numeric with an ISO currency code (GBP) so formatting is consistent. See the browser Intl formatter documentation for locale-aware output and the UTF-8 glossary for encoding details: Intl.NumberFormat, UTF-8, ISO 4217 currency codes.

Recommended Answers

All 2 Replies

In a shop, you set the prices in whatever currency is appropriate.

The user should never need to enter a currency symbol and you should never need to read/deltect one in its symbolic "£" "$" form.

If your shop has user-selectable currency modes, and your client-side or server-side code needs to know what currency was selected, then write a coded "currency value" into a hidden form field, eg. USD=1, UKP=2, Rupee=3 etc. Change this value whenever the currency mode is changed. Alternatively, if currency is selected from a <select> menu, then simply read the current (coded) value from the select element; no hidden form field is necessary.

Airshow

hi all

trying to set up an online shop BUT..

cant get javascript to accept "£" so having to use "$" instead..not good for a uk site lol

Use the character entity &pound;.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.