Click to See Complete Forum and Search --> : So you think your a good coder?
Code One
03-27-2003, 04:01 PM
You probably are ;) . . . anyway see if you can do this:
<html>
<head>
<title>Line Breaks</title>
<script langugae="javascript" type="text/javascript">
function addbr(frm)
{
val = frm.mytext.value;
val = val.replace(/\n/g,"<br>");
document.getElementById("mydiv").innerHTML = val;
newval = document.getElementById("mydiv").innerHTML;
newval = newval.replace(/<br>/gi,"<br>\n");
document.myform2.mytext2.value = newval;
}
</script>
</head>
<body>
<form name="myform" onSubmit="addbr(this); return false;">
<textarea name="mytext" cols="50" rows="8"></textarea>
<br>
<input name="submit" type="submit" value="Submit">
</form>
Live Preview:
<div id="mydiv" style="width: 420px; height: 180px; border: 1px solid; overflow: auto;"></div>
<br>
Code Generated:
<form name="myform2">
<textarea name="mytext2" cols="50" rows="8"></textarea>
</form>
</body>
</html>
=========================================
I would like for this code to work in one textarea ONLY! I am totally stumped I have been working on this problem forever and I still can't figure out how to make it happen all with one textarea. As you can see the process is done using two textareas and a div id input. I would really like to get rid of one of the textareas and the div thing so that all the above works in one textarea. Got it? I bet you do. Anyhelp, anyone
Thanks in advance
Code One
Code One
03-27-2003, 05:52 PM
Someone in another forum just asked me to reinterate also, I must not be speaking clear, ;)
Ok Ill give it to you guys how I gave it to him:
Ok, heres what Im trying to do:
description: In this layout there are three boxes.
a. textarea
b. live input
c. textarea
----------------------------------------------------
In the first textarea (box) is were you type stuff ex:
blah
blah
(then you click submit)
-----------------------------------------------------
Once submit has been fired the text you typed will display in the live input box and the second textarea (box). In the live input box the text will look exactly like the way you typed it in the first textarea (box). In the second textarea box the text will look like this:
blah <br>
blah
-------------------------------------------------------
A more percise visual:
(Textarea01)
============================
blah
blah
============================
(end textarea01)
<input type="submit"> <--click to fire--|
(live input box)
============================
blah
blah
============================
(end live input box)
(textarea02)
============================
blah <br>
blah
============================
(end textarea02)
------------------------------------------------------
The above diagram is what the page looks like after the user has typed something and clicked submit. As you can see the last textarea displays the text which was typed in the first textarea except with a br tag automatically inputed by the script. Which is great! But not exactly what Im looking to do.
---------------------------------------------------------
What I want:
I would simply like a method in which I could still have the auto br happen, but I would like to eliminate the live input box and the second textarea, so that the entire process happens in one textarea ONLY.
---------------------------------------------------------
Now do you understand what I mean, I hope so I don't know how else to explain. ;) Thanks for the interest hope you can help.
Code One
Code One
03-27-2003, 06:36 PM
That must seem pretty stupid of me . . . I guess I just neevr tried to do that before. Wow new concept, thats pretty rad. Well tell me what can I use to make the html live, (input?)
And if so can I make the auto br happen in that? and just that?
Thanks for the info!
Code One
edit: Hey Dave let me ask you do you and the other moderators work in the same place, I mean like if you wanted to give pyro a high five could you do that like right now?
Code One
03-27-2003, 07:30 PM
Despite me giving you guys a hard time, (sometimes), I think the info you offer is priceless. I have never had more help and learned more anywere else. I learned more here than I did in school. ;)
Seriously though you guys are awesome and I enjoy coming here.
Anyway, The example was pretty cool, I didnt get much from the view, so I checked out the source, and I understand how it works, I wonder if I can just make all the code above work in the div tag. Im going to try that, but hey if you happen to have a good idea please dont hesitate to throw your two cents in. I love pennies ;)
Thanks Dave!
Code One
edit: Oh one more thing, I have a textarea in another program I coded and it has a textarea and when the user types in stuff, like:
blah
blah
blah
and blah
(and then saves it using the save button)
The text runs together. But if the user adds the <br> tag at the end of the text like:
blah < br >
blah < br >
blah < br >
and blah < br >
(and saves it using the save button)
the text looks like the original text, minus the br tag, isnt that an example of live html within a textarea?
Originally posted by Code One
Well tell me what can I use to make the html live, (input?)Try my original code: http://forums.webdeveloper.com/showthread.php?s=&threadid=6627 As Dave pointed out, a textarea cannot render HTML, so you will want at least two different boxes.
Code One
03-28-2003, 02:53 PM
I tried your code already and is what Im basing my new questions on. I think the code is great but not exactly what I'm looking for. Let me ask you this:
Is it possible to limit that code down to one box, so that everything happens in just one box. I would really like to exclude the live feed box, and the second textarea if possible. So that I could have the auto br script processing in one box, wether it be a box witin a div tag, a input, or textarea, just as long as the function of the auotmatic br tag insertation is happening in just one box and one box alone. If you could help that would be much appreciated.
Thanks alot!
Code One
Code One
03-28-2003, 03:22 PM
I managed to work it out heres my code:
<html>
<head>
<title>Line Breaks</title>
<script langugae="javascript" type="text/javascript">
function addbr(frm)
{
val = frm.mytext.value;
val = val.replace(/\n/g,"<br>");
document.getElementById("mydiv").innerHTML = val;
newval = document.getElementById("mydiv").innerHTML;
newval = newval.replace(/<br>/gi,"<br>\n");
document.myform.mytext.value = newval;
document.getElementById('submit').disabled = true;
}
</script>
</head>
<body>
<form name="myform" onSubmit="addbr(this); return false;">
<textarea name="mytext" cols="50" rows="8"></textarea>
<br>
<input name="submit" type="submit" value="<br>"> <input type="button" onclick="history.go()" value="reset">
</form>
<div id="mydiv" style="display:none;width: 420px; height: 180px; border: 1px solid; overflow: auto;"></div>
</body>
</html>
Hope you guys find this code to your likeing, be good!
Code One