I have the following variable -
termText = $("#termBox").val();
where $("#termBox").val() is equal to - "\"Test\""
I then am creating an html object and want to set its value to termText like -
<input type="text" id="secondBox" value="' + termText + '">
However this is not working. The odd thing is when $("#termBox").val() does not have double quotes in it i.e. "Test" (in javascript debugger is adding the quotes to show it is a string), this works fine and populates secondBox value perfectly.
I dont want to escape double quotes from the string as they are required as there has to be a definition between when a user enters "Term" or Term however this is not working for double quotes.
How can I do this?
You have to escape it with html equivalent when you create input.
<input type="text" id="secondBox" value="' + termText.replace(/\"/g,""") + '">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With