Echo var from PHP into textarea control -
desired outcome: define string var in php , echo textarea control contents.
problem: textarea contains:
</body> </html> index.php:
<?php $y = "bonkers"; ?> <html> <body> here textarea control:<br /> <textarea id='mytext' rows="30" cols="120" value='<?php echo $y; ?>' /> </body> </html>
<textarea> doesn't have html value attribute. therefore, correct way set text within textarea follows:
<textarea id="mytext" rows="30" cols="120"><?php echo $y; ?></textarea> you can access within javascript or jquery, however, normal input field.
// jquery example $("textarea#mytext").val(); the reason why textarea contains ending body , html tags due how <textarea> closed; it's meant used <textarea></textarea>, not <textarea />. (reference)
Comments
Post a Comment