TheUndecider
asked on
Javascript to Insert a break line in TextArea boxes
Hello,
I'm working on a web page and I have these read only text areas where the user enters several options for the products they want. When they enter these options I am able to create text boxes for each input, but when they go to the next page, all entered text becomes read only and it's displayed in one single textarea. All fields are separated by a comma.
Is there a way that I can create a javascript code that looks for any textarea in the page, look for their content and enters a break <br> before a comma so the text looks easier to read? These breaks are only for visual purposes, I don't want to edit the field values. I just want them to look better than one single line.
Here's 2 textareas where you can see what I'm talking about.
<textarea readOnly class="cart" wrap="physical" name="0:freeopt" rows="4" cols="40" ID="Textarea1">Product,Wid get,Type,B ucket,Colo r,Blue</te xtarea>
<textarea readOnly class="cart" wrap="physical" name="1:freeopt" rows="4" cols="40" ID="Textarea2">Product,She ll,Type,Wo od,Color,R ed</textar ea>
I need them to look like this:
Product,
Widget,
Type,
Bucket,
Color,
Blue
Any ideas?
Thanks!
I'm working on a web page and I have these read only text areas where the user enters several options for the products they want. When they enter these options I am able to create text boxes for each input, but when they go to the next page, all entered text becomes read only and it's displayed in one single textarea. All fields are separated by a comma.
Is there a way that I can create a javascript code that looks for any textarea in the page, look for their content and enters a break <br> before a comma so the text looks easier to read? These breaks are only for visual purposes, I don't want to edit the field values. I just want them to look better than one single line.
Here's 2 textareas where you can see what I'm talking about.
<textarea readOnly class="cart" wrap="physical" name="0:freeopt" rows="4" cols="40" ID="Textarea1">Product,Wid
<textarea readOnly class="cart" wrap="physical" name="1:freeopt" rows="4" cols="40" ID="Textarea2">Product,She
I need them to look like this:
Product,
Widget,
Type,
Bucket,
Color,
Blue
Any ideas?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
A break-tag (<br />) won't work inside a textarea. In JavaScript you would print a break character, "\n". This may vary depending on the language you're using.
<textarea rows="12" cols="50" id="myText"></textarea>
<script type="text/javascript">
document.getElementById('myText').innerHTML = "hello\nworld";
</script>
ASKER
Thanks! It really worked!
Open in new window