I am trying to store text from textarea with localstorage. It works just fine, but when i insert line breake it does nothing.
<textarea cols="50" rows="10" name="text" id="contact_text" class="inputbox required"></textarea>
<script>
document.getElementById("contact_text").innerHTML=localStorage.getItem("kommentaar");
var that = "<?php $text = JRequest::getVar('text'); echo $text; ?>";
localStorage.setItem('kommentaar',that);
</script>
Example: When "Hello, world!" is entered to textarea and the script is runned it works, but when
"Hello,
world!"
What am i doing wrong???
There is no matter with and without line break for getting text from textarea. Because this below example is running with both conditions.
<!DOCTYPE html>
<html>
<body>
<textarea cols="50" rows="10" name="text" id="contact_text" class="inputbox required"></textarea>
<br />
<input type="button" onclick="saveValue()" value="save value"/>
<script>
function saveValue(){
if(typeof(Storage)!=="undefined"){
var value = document.getElementById('contact_text').value;
localStorage.setItem('val', value);
alert(localStorage.getItem('val'));
}
}
</script>
</body>
</html>
Perhaps your problem is in this statement var that = "<?php $text = JRequest::getVar('text'); echo $text; ?>";
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.