I am getting an error while i am registering php variable to html form element through javascript. Like If In my code there is php variable $edu_notes
and i am assigning this variable's value to a html form element that is
<textarea name="1_1_50" id="1_1_50" ></textarea>
and My Javascript code is :
document.getElementById('1_1_50').value = "<?php echo $edu_notes; ?>";
the value of $edu_notes
comes from linkedin profile which is :
"First Text Line
Second Text Line"
there is a gap of blank line between its first text line and second text line. And the javascript gives an error that is
unterminated string literal
"First Text line
Javascript is not getting the full value as a string because of blank line. I have tried some php functions like filter_var(),nl2br(),trim()
but not resolving this issue. I have also tried to type cast through (string) $edu_notes
.
In my source file what i am getting please see screenshot below :
I am doing this type of functionality because all the form elements are coming from database dynamicaly.