AAAAARRRGGGHHHHHHH!!!!!!!!!!!!!!!!

Sorry, but thats how much I was frustrated when I could not get a
simple thing to work on a static html page using javascript. I just
wanted to insert a line break into the textarea dynamically. Here is
the piece of code that will not work... but will give you a "unknown
runtime error". If you remove the "<br>"s, it will work.



<html>
<head>
<script language="JavaScript">
function writeText() {
document.all.myTextArea.innerHTML =
"Hello<br>" + "sometext" + "<br>Hello";
//THIS WONT WORK EITHER:
//document.all.myTextArea.innerHTML =
// "Hello\n" + "sometext" + "\nHello";
}
</script>

</head>
<body>
<table>
<tr><td id="mytd"><textarea
id="myTextArea"></textarea></td></tr>
<tr><td><input type="submit" name="submit" value="submit"
onClick="writeText();"/></td></tr>
</table>

</body>
</html>




But Internet Explorer did not like it. I visited a lot of newsgroups
and tried different things. I've tried replacing line breaks ("\n")
with <br>s and what not... but we wont go into it. What I am trying
to
say here is that I could not find a way to format the text inside a
text area. After hours of research, I just ended up doing something
like this... which by the way occured to me when I was finishing up
my
Dominos pineapple pizza. The workaround was to include the whole
textarea inside the javascript and write them into the TD using the
innerHTML of the TD at runtime. I sincerely hope that this will help
someone solve a similar issue and save them a lot of trouble.

=========
SOLUTION:
=========

Here is the code that I came up with to work around this situation...


//THIS IS THE WORKAROUND: (result is the id of TD, so you are
basically inserting html that CONTAINS the textarea into the TD
instead of writing text to the textarea. i.e., you are writing the
whole textarea into the TD at runtime)

<html>
<head>
<script language="JavaScript">
function writeText() {
var rslt;
rslt = "<textarea id=\"myTextArea\">";
rslt += "Hello\n" + "sometext" + "\nHello";
document.all.mytd.innerHTML = rslt + "</textarea>";
}
</script>

</head>
<body>
<table>
<tr><td id="mytd"> <textarea id="myTextArea"></textarea>
</td></tr>
<tr><td><input type="submit" name="submit" value="submit"
onClick="writeText();"/></td></tr>
</table>

</body>
</html>


GOOD LUCK!!!

You are welcome.

Jawad Shaik Mohammed
Stryker Instruments
Kalamazoo, MI
Ph: (269) 323-7700 x3500

Re: Formatting or inserting breaks into Textarea using innerHTML by Mythran

Mythran
Mon Jul 28 15:17:06 CDT 2003

<script language="VBScript">
Sub cmdInsertLineBreak_OnClick()
Dim Value

Value = txtMyText.innerText

txtMyText.innerText = Left(Value, Len("Place the line break here")) & vbCrLf
& Mid(Value, InStrRev("Now I can see.")))
End Sub
</script>


<body>
<textarea name="txtMyText" cols="20" rows="20" wrap="hard">Place the line break
hereNow I can see.</textarea>
<br>
<input type="button" name="cmdInsertLineBreak" value="Insert Line Break">
</body>


Try the above, untested.

Mythran



Re: Formatting or inserting breaks into Textarea using innerHTML by Csaba2000

Csaba2000
Tue Jul 29 01:00:46 CDT 2003

I think this is what you want in Javascript:
document.all.myTextArea.value = "Hello\n" + "sometext" + "\nSo long";

Note that .value has replaced .innerHTML

Csaba Gabor

"Jawad Shaik Mohammed" <shaikjawad@yahoo.com> wrote in message
news:f471bc88.0307281202.3dc5a129@posting.google.com...
> AAAAARRRGGGHHHHHHH!!!!!!!!!!!!!!!!
>
> Sorry, but thats how much I was frustrated when I could not get a
> simple thing to work on a static html page using javascript. I just
> wanted to insert a line break into the textarea dynamically. Here is
> the piece of code that will not work... but will give you a "unknown
> runtime error". If you remove the "<br>"s, it will work.
>
>
>
> <html>
> <head>
> <script language="JavaScript">
> function writeText() {
> document.all.myTextArea.innerHTML =
> "Hello<br>" + "sometext" + "<br>Hello";
> //THIS WONT WORK EITHER:
> //document.all.myTextArea.innerHTML =
> // "Hello\n" + "sometext" + "\nHello";
> }
> </script>
>
> </head>
> <body>
> <table>
> <tr><td id="mytd"><textarea
> id="myTextArea"></textarea></td></tr>
> <tr><td><input type="submit" name="submit" value="submit"
> onClick="writeText();"/></td></tr>
> </table>
>
> </body>
> </html>
>
>
>
>
> But Internet Explorer did not like it. I visited a lot of newsgroups
> and tried different things. I've tried replacing line breaks ("\n")
> with <br>s and what not... but we wont go into it. What I am trying
> to
> say here is that I could not find a way to format the text inside a
> text area. After hours of research, I just ended up doing something
> like this... which by the way occured to me when I was finishing up
> my
> Dominos pineapple pizza. The workaround was to include the whole
> textarea inside the javascript and write them into the TD using the
> innerHTML of the TD at runtime. I sincerely hope that this will help
> someone solve a similar issue and save them a lot of trouble.
>
> =========
> SOLUTION:
> =========
>
> Here is the code that I came up with to work around this situation...
>
>
> //THIS IS THE WORKAROUND: (result is the id of TD, so you are
> basically inserting html that CONTAINS the textarea into the TD
> instead of writing text to the textarea. i.e., you are writing the
> whole textarea into the TD at runtime)
>
> <html>
> <head>
> <script language="JavaScript">
> function writeText() {
> var rslt;
> rslt = "<textarea id=\"myTextArea\">";
> rslt += "Hello\n" + "sometext" + "\nHello";
> document.all.mytd.innerHTML = rslt + "</textarea>";
> }
> </script>
>
> </head>
> <body>
> <table>
> <tr><td id="mytd"> <textarea id="myTextArea"></textarea>
> </td></tr>
> <tr><td><input type="submit" name="submit" value="submit"
> onClick="writeText();"/></td></tr>
> </table>
>
> </body>
> </html>
>
>
> GOOD LUCK!!!
>
> You are welcome.
>
> Jawad Shaik Mohammed
> Stryker Instruments
> Kalamazoo, MI
> Ph: (269) 323-7700 x3500