How do I set the value between the TEXTAREA tags?

L

laredotornado

Hi,

If my variable contains

var v = "Hi<BR/>there<BR/>";

and attempt to set the value of my textarea like so:

dojo.byId("appEditForm:txtDesc").value = v;

I actually see the "<BR/>" tags displayed on the screen. I don't want
this -- preferring to see line breaks. What is the proper way to set
the HTML between TEXTAREA tags?

Thanks, - Dave
 
A

ameshkin

Dave,
the best way to do this is with PHP/AJAX. But this may not be your
best option depending on what you're doing. I use the below code
becasue its simple, but there are many frameworks that can squeeze
this done to one line of code.


function ajxPost(){
var ajaxRequest;

try{
// Opera 8.0+, Firefox, Safari
ajaxRequest = new XMLHttpRequest();
} catch (e){
// Internet Explorer Browsers
try{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e){
// Something went wrong
alert("Your browser broke!");
return false;
}
}
}
// ajax function
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
var ajaxDisplay = document.getElementById('textarea-id');
ajaxDisplay.innerHTML = ajaxRequest.responseText;
}
}


var queryString = "?variable=" + variable+ "&bankid=" + bankid;

ajaxRequest.open("GET", "php-file-with-content.php" + queryString,
true);
ajaxRequest.send(null);
}
 
R

RoLo

Hi,

If my variable contains

var v = "Hi<BR/>there<BR/>";

and attempt to set the value of my textarea like so:

dojo.byId("appEditForm:txtDesc").value = v;

I actually see the "<BR/>" tags displayed on the screen.  I don't want
this -- preferring to see line breaks.  What is the proper way to set
the HTML between TEXTAREA tags?

Thanks, - Dave

Theres no way to do it, its like asking the proper way to set an
iframe inside a textarea...
theres a reason its called TEXTAREA!

if you only want to convert <br/> to \n, then you should do something
like,
dojo.byId("appEditForm:txtDesc").value = v.replace(/<br\/>/ig,"\n");
 
A

ameshkin

Now that I think about it, I do not believe this will work for a text
area. It may not be necessary to put a text area here, and you may
want to use a div instead. this all depends on exactly what you are
doing.

Sorry i could not be more help, but I'm very very new to JS myself and
I have trouble doing the easiest things.
 
S

Suhas Dhoke

I actually see the "<BR/>" tags displayed on the screen.  I don't want
this -- preferring to see line breaks.  What is the proper way to set
the HTML between TEXTAREA tags?

Then, use the new line feed ("\n") instead of "<BR/>".

Hope, this will helps you.
 
T

Thomas 'PointedEars' Lahn

Suhas said:
Then, use the new line feed ("\n")

There is no character with that name. There is the Line Feed (LF) character
(escape sequence: "\n") and the Carriage Return (CR) character ("\r"). Both
are used for creating a new line: "\r\n" is used on WinDOS, "\n" is used on
Unices, and "\r" is used on Mac OS up to version 9, among others.
Therefore, it is probably best to use the escape sequence "\r\n" as it
satisfies all conceivable markup parsers, including standards-compliant ones.
instead of "<BR/>".

<BR/> is not likely to be Valid markup anyway. If it should be HTML, then
it should be <BR>, <Br>, <bR> or <br> (else it would be equivalent to
"<BR>&gt;". If it should be XHTML (which should only be used on today's Web
instead of HTML when absolutely necessary), then it must be <br/>, <br /> or
<br></br> (XHTML is case-sensitive), whereas the second form is deemed
"HTML-compatible" (because many of not most markup parsers do not implement
the HTML SHORTTAG feature properly).


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top