Menu
Hi all,
I have a script which adds <br> tag to the textarea when you press Enter. Text area looks like:
My name is John<br>I am 22 years old.
Does anyone have a script which hides this <br> code and gives it to the output of the form? I need the text area look like:
My name is John
I am 22 years old
but the info sent to be My name is John<br>I am 22 years old.
Thanks
[CODE]textarea{white-space:pre}[/CODE]
in your stylesheet.<html>
<script type="text/javascript">
function addBreak(obj){
var t = obj.text;
if((window.event && window.event.keyCode == 13)||(event && event.which == 13))
t+='n';
obj.text=t;
return;
}
</script>
</head>
<body>
<textarea onkeyup="addBreak(this)">
</textarea>
</body>
</html>
function replaceIt(text){
var tt='';
var ttt=text;
while(ttt.match('n'))
{
tt=ttt;
ttt=tt.replace('n','<br>');
}
alert(ttt)
return (ttt);
}
<i>
</i>while(ttt.match('n'))
{
tt=ttt;
ttt=tt.replace('n','<br>');
}
[/QUOTE]
<i>
</i>ttt = ttt.replace(/n/g,"<br/>");
Err... why the while? Replace that whole thing with...
<i>
</i>ttt = ttt.replace(/n/g,"<br/>");
..otherwise you are wasting the power of the RE.. ?[/QUOTE]
Err... why the while? Replace that whole thing with...
<i>
</i>ttt = ttt.replace(/n/g,"<br/>");
..otherwise you are wasting the power of the RE.. ?[/QUOTE]
Er..
1) Then surely the purpose is to improve the OP's understanding of the possibilities of RE rather than write superfluous and wasteful code.
2) You might want to check up on the power of RE as you can pass functions in as the second parameter for the replace, allowing you to set your conditionals as you suggest (even if it's highly unlikely from the original question).[/QUOTE]
This is obviously a difference of opinion relating to how information is passed to those asking. Me? I like provide the person with the best solution I can think of, if that involves complicated techniques then that is simply the fact of life as a programmer.
C'est la vie, eh? At least the OP has had (if they bothered to check the thread once their answer has been received, that is) the opportunity to see several solutions.[/QUOTE]
I have not taken offense to anything that you have said. I was simply doing the same as you, so please don't get upset.
[/QUOTE]
In computer science, abstraction is a mechanism and practice to reduce and factor out details so that one can focus on a few concepts at a time.
[/quote]
In object-oriented programming theory, abstraction is the facility to define objects that represent abstract "actors" that can perform work, report on and change their state, and "communicate" with other objects in the system.
[/quote]
is about the "reusability" of the code for more purposes than just the basic one needed.[/QUOTE]
0.1.9 — BETA 5.26