Chrex Posted January 27, 2015 Share Posted January 27, 2015 Hi guys, I need to work with "m³". The function in my script gets a value from a selection. I have 10 seletion options. It works fine with 9 of them, just the "m³" doesnt work. I read something about unicode, but couldn´t find the right one (if it exist für ^3). I also had a look at the w3 js pages (number, math), but that didn´t help too. if (abc == "m³") { var variable = "m³"; document.getElementById('show').innerHTML = variable;} Thanks for your hints, Chrex Link to comment Share on other sites More sharing options...
Ingolme Posted January 27, 2015 Share Posted January 27, 2015 If you're using the <select> dropdown list. What you can do is make the value of the <option> element a string that's easier to work with. For example: <option value="m3">m³</option> Link to comment Share on other sites More sharing options...
justsomeguy Posted January 27, 2015 Share Posted January 27, 2015 Javascript supports unicode, you can even use unicode identifiers. What does "doesn't work" mean, what happens? Link to comment Share on other sites More sharing options...
Chrex Posted January 27, 2015 Author Share Posted January 27, 2015 @Foxy Mod: That doesn´t work for me. I also use the value in php and it will be shown at one place, so it needs to be "m³". @justsomeguy: "doesn´t work" means, my script/function doesn´t work with the value and doesn´t show the value. I had the same problem with "ä" and I could solve it by replacing the "ä" with "u00e4". I thought there is something like that for "m^3". Link to comment Share on other sites More sharing options...
justsomeguy Posted January 27, 2015 Share Posted January 27, 2015 Make sure your files are saved as unicode files, not ASCII or whatever else.Here's the code point for superscript 3. Link to comment Share on other sites More sharing options...
Chrex Posted January 27, 2015 Author Share Posted January 27, 2015 Hmmm, thanks for the link. I found this: "u33A5", but it doesn´t work. My files should be saved in the right format, because it works with "ä", right? Link to comment Share on other sites More sharing options...
Ingolme Posted January 27, 2015 Share Posted January 27, 2015 Open your text editor and figure out what encoding the page has. It should be UTF-8. If it's ANSI or something else then you need to change it. Link to comment Share on other sites More sharing options...
Chrex Posted January 27, 2015 Author Share Posted January 27, 2015 Just found something which says "UTF-8". Link to comment Share on other sites More sharing options...
justsomeguy Posted January 27, 2015 Share Posted January 27, 2015 What else have you tried? Have you checked whether the if statement succeeds or fails, or is the innerHTML line the problem? Are there any messages in your browser's developer console? What happens if you use console.log to check the value of abc? Link to comment Share on other sites More sharing options...
Chrex Posted January 27, 2015 Author Share Posted January 27, 2015 (edited) The problem has to be the "if-code". The "if" doesn´t agree that abc == "m³". I figured that out by changing the code to: if (abc == "m³") { var variable = "m"; document.getElementById('show').innerHTML = variable;} If the "if-code" would work, I would get "m". I´m very sure the innerHTML works, because it does work with all the other variables. Edited January 27, 2015 by Chrex Link to comment Share on other sites More sharing options...
Ingolme Posted January 27, 2015 Share Posted January 27, 2015 Check what value abc has: if (abc == "m³") { var variable = "m³"; document.getElementById('show').innerHTML = variable;} else { // Why isn't it working? alert(abc);} Link to comment Share on other sites More sharing options...
Chrex Posted January 27, 2015 Author Share Posted January 27, 2015 Hmmm, the alert says: m³ Link to comment Share on other sites More sharing options...
Jonathanks Posted January 27, 2015 Share Posted January 27, 2015 Then I think it's how m^3 should be displayed in HTML you should figure out. Dunno if I'm right, but try m<sup>3</sup>. Link to comment Share on other sites More sharing options...
Ingolme Posted January 27, 2015 Share Posted January 27, 2015 Where is the variable "abc" being set? Link to comment Share on other sites More sharing options...
Chrex Posted January 27, 2015 Author Share Posted January 27, 2015 @Jonathanks: I tryed this "<sup>3</sup>" already...it doesnt work. @Ingolme: The variable is set in front of the "if-code", right after the start of the function. function show_selection(){var abc = document.getElementById('abc').value; if (abc == "m³") { var variable = "m³"; document.getElementById('show').innerHTML = variable; }} Link to comment Share on other sites More sharing options...
justsomeguy Posted January 27, 2015 Share Posted January 27, 2015 Make sure everything is using UTF-8, the file encoding and also a meta tag on the page to specify the character set. Javascript itself should have no problem with that, if you set the variable to that value manually then it should work fine, it seems like there is a problem reading the value. The page's character set might fix that. Link to comment Share on other sites More sharing options...
Chrex Posted January 30, 2015 Author Share Posted January 30, 2015 hmmm, my page works with UTF-08: <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> ...and my script too: <script type="text/javascript" charset="UTF-8" src="show.js"> Everything works, when I replace "m³" with "m". How I said, I had the same problem with "ä, ö, ü", but I could solve it by using "u00f6". But u33a5" doesn´t work for "m³". Link to comment Share on other sites More sharing options...
Ingolme Posted January 30, 2015 Share Posted January 30, 2015 It doesn't matter what the <meta> tag says. If the page isn't actually UTF-8, telling the browser that it is won't work. Your text editor needs to save it with that encoding. Which editor are you using? Link to comment Share on other sites More sharing options...
Chrex Posted January 30, 2015 Author Share Posted January 30, 2015 Expression Web 4 Link to comment Share on other sites More sharing options...
Ingolme Posted January 30, 2015 Share Posted January 30, 2015 I think it might be UTF-8 by default, but just in case, here are some instructions on how to change the entire site's encoding and the encoding for just one page. For the whole site: On the Site menu, click Site Settings, and then click the Advanced tab. In the Default page encoding list, select the page encoding that you want as a default setting for the active site. If you do not want Expression Web to verify that the encoding matches your keyboard settings, select the Ignore the keyboard when deciding the encoding of new pages check box. For just one page: On the File menu, click Properties, and then click the Language tab. In the Page Properties dialog box, under HTML encoding, in the Save the document as box, select the page encoding that you want. Here are the manual pages https://msdn.microsoft.com/en-us/library/cc294982%28v=expression.40%29.aspx https://msdn.microsoft.com/en-us/library/cc295274%28v=expression.40%29.aspx Link to comment Share on other sites More sharing options...
Chrex Posted January 30, 2015 Author Share Posted January 30, 2015 It says: UTF-8 Link to comment Share on other sites More sharing options...
Ingolme Posted January 30, 2015 Share Posted January 30, 2015 I don't really understand why it's not working. Can you show an example page online or give all the code necessary to recreate the problem ourselves? Link to comment Share on other sites More sharing options...
Chrex Posted January 30, 2015 Author Share Posted January 30, 2015 Thanks to everyone again, especially to Ingolme (he delivered the solution). The formate of the script was ANSI, so I had to change it with "Encode in UTF-8". No idea why it didn´t work right away after clicking on "Encode in UTF-8", but after a few conversions (ANSI, Encode in UTF-8, Concert to UTF-8) it works. You can´t do this with Expression Web 4, I used Notepad++. Hope it will help someone with the same problem. Cheers, Chrex Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now