Jump to content

How to work with "m³"


Chrex

Recommended Posts

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

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

@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

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

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 by Chrex
Link to comment
Share on other sites

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

@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

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

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

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

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:

 

  1. On the Site menu, click Site Settings, and then click the Advanced tab.
  2. In the Default page encoding list, select the page encoding that you want as a default setting for the active site.
  3. 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:

 

  1. On the File menu, click Properties, and then click the Language tab.
  2. 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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...