0

i have a long String. With some German characters and lots of new lines tabs ect.. In a Selectbox user can select a text, on change i do

document.getElementById('text').value=this.value;

But this fails. I just get a "unterminated string literal" as error in JavaScript.

I think i should clean the string.

How can i do it in JavaScript?

6
  • 5
    I don't think the string value is the problem here, I think there is some pure syntax error in your script. Commented Apr 27, 2010 at 8:21
  • syntax error? but why do i get a unterminated string literal ? Commented Apr 27, 2010 at 8:22
  • @streetparade: Using var x = 'hello; will probably give you the same error, because the string doesn't end anywhere, as there is no closing apostrophe, i.e. '. Commented Apr 27, 2010 at 8:24
  • if you want clean the string, just assign the null value. document.getElementById('text').value=""; Commented Apr 27, 2010 at 8:24
  • Yes that could be the problem, but in that string there are also some ' or " Commented Apr 27, 2010 at 8:25

2 Answers 2

4

Its not because of that code, there is syntax error somewhere in your javascript file.

For example, in one of your previous question's answer

 alert("yes link clicked); 

You could see, there is " is missing after clicked, which could cause unterminated string literal error. Fix it like

 alert("yes link clicked"); 
Sign up to request clarification or add additional context in comments.

Comments

1

As I cannot judge from your code, you might want to check what this in this.value refers to, e.g. using an alert("debug: " + this.value) .

Other than that, you might want to use encodeURI() for converting umlauts and other special characters to hexadecimal notation. If your page's content-type is set to UTF-8 special characters will then display correctly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.