0

the problem is the string value is a dynamic value, sometimes i have data with double quote character, so javascript cant read full of the string value from the data.

I made a manipulation, i put the value on html input, and set the variable with the html input value. But, i found the same problem, if the value have double quote character, the variable cannot take all the value. The element show like this:

<input type="hidden" id="soal7" value="Boyolali regency is located in north of Solo and east of Merapi and Merbabu Mountains. This regency has been known for its production of fresh milk for a long time. No wonder, the cow statues adorn Boyolali town.<br>
There are six main cow statues in Boyolali. They are displayed in different places.However, the size is made bigger to catch the eye.<br>
Besides decorating the town, the statues also turn out to be helpful for people from out of town to find places they are seeking in Boyolali. By mentioning the position of the statue, people can get their way easily.<br><br>" ...="" <u=""> they are seeking in Boyolali" (paragraph 3)<br>What does the underlined word refer to?">

the value must be

Boyolali regency is located in north of Solo and east of Merapi and Merbabu Mountains. This regency has been known for its production of fresh milk for a long time. No wonder, the cow statues adorn Boyolali town.
There are six main cow statues in Boyolali. They are displayed in different places.However, the size is made bigger to catch the eye.
Besides decorating the town, the statues also turn out to be helpful for people from out of town to find places they are seeking in Boyolali. By mentioning the position of the statue, people can get their way easily.

"they are seeking in Boyolali" (paragraph 3)
What does the underlined word refer to?

the bold text have double quotes, so the input type cannot set all of the string

is there any idea to manipulate this ?

2 Answers2

0

You can have double quotes in strings, you just need to escape them with the \ char. Keep in mind, if the string is incoming from an api or something like that, you may need to write some code to escape them manually.

const myString = '\"Hello\"';
console.log(myString);
mwilson
  • 12,295
  • 7
  • 55
  • 95
  • thank you, but i have dynamic string value, so i cant manually use it – Fikri Ali Thaufik Jan 16 '20 at 02:52
  • That's where the manual part comes in. You'll need to create some code to strip the quotes manually. It might be worth providing a better example via code snippet that produces the error/issue you're running into so we can help you out. – mwilson Jan 16 '20 at 02:57
0

You can use &quot; for this:

<input type="text" value="single ' and double &quot;"/>

Here's the full snippet for your code. I changed it from type="hidden" to type="text" so you could read it.

<input type="text" id="soal7" value="Boyolali regency is located in north of Solo and east of Merapi and Merbabu Mountains. This regency has been known for its production of fresh milk for a long time. No wonder, the cow statues adorn Boyolali town.<br>There are six main cow statues in Boyolali. They are displayed in different places.However, the size is made bigger to catch the eye.<br>Besides decorating the town, the statues also turn out to be helpful for people from out of town to find places they are seeking in Boyolali. By mentioning the position of the statue, people can get their way easily.<br><br>&quot; ...=&quot;&quot; <u=&quot;&quot;> they are seeking in Boyolali&quot; (paragraph 3)<br>What does the underlined word refer to?"/>
Aaron Plocharczyk
  • 2,776
  • 2
  • 7
  • 15