Jump to content
Sign in to follow this  
Chrex

How to work with "m³"

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

Share this post


Link to post
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>

Share this post


Link to post
Share on other sites

Javascript supports unicode, you can even use unicode identifiers. What does "doesn't work" mean, what happens?

Share this post


Link to post
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".

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
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);}

Share this post


Link to post
Share on other sites

Where is the variable "abc" being set?

Share this post


Link to post
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;	}}

Share this post


Link to post
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.

Share this post


Link to post
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³".

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...