简体   繁体   中英

Populate file contents in value field of a text box

I created a text box as follows-

<textarea name ="textbox" rows="20" cols="50" id ="textbox" style="background-color: #000000; font-size:14.5px; font-family:arial; color:#FFFFFF;"> </textarea>';

In the PHP script,I am trying to get the contents of a file and then trying to populate the value field of the textbox as follows :

echo '<script> document.getElementById("textbox").value = "'.$final1.'";</script>';

where $final1 = file_get_contents(FILENAME);

I see that there is nothing populated in the value field and neither do i see any output when I try to echo this variable. I tried giving a variable say $test = "ABCD"; and populating this variable and it worked.

I know this has something to do with HTML special characters because my file has lot of special characters but I am not able to find a solution.

Kindly please help. Thanks!

If you problem is related to the file you load having special characters in to that html/javascript does not like try this

$final1 = htmlspecialchars( file_get_contents(FILENAME) );
echo '<script> document.getElementById("textbox").value = "'.$final1.'";</script>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM