How do I set the value between the TEXTAREA tags?

Discussion in 'Javascript' started by laredotornado, Jul 21, 2008.

  1. 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
    laredotornado, Jul 21, 2008
    #1
    1. Advertising

  2. laredotornado

    ameshkin Guest

    On Jul 21, 10:32 am, laredotornado <> wrote:
    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);
    }


    > 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
    ameshkin, Jul 21, 2008
    #2
    1. Advertising

  3. laredotornado

    RoLo Guest

    On Jul 21, 1:32 pm, laredotornado <> wrote:
    > 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");
    RoLo, Jul 21, 2008
    #3
  4. laredotornado

    ameshkin Guest

    On Jul 21, 10:32 am, laredotornado <> wrote:
    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.






    >
    > 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
    ameshkin, Jul 21, 2008
    #4
  5. laredotornado

    Suhas Dhoke Guest


    > 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.
    Suhas Dhoke, Jul 22, 2008
    #5
  6. Suhas Dhoke wrote:
    >> 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")


    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
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
    Thomas 'PointedEars' Lahn, Jul 22, 2008
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Augustus
    Replies:
    1
    Views:
    335
    Ken Schaefer
    Sep 10, 2003
  2. Textarea Inside of a textarea

    , Feb 4, 2006, in forum: ASP General
    Replies:
    6
    Views:
    314
    Anthony Jones
    Feb 5, 2006
  3. Chris Kennedy
    Replies:
    1
    Views:
    140
    Michael Winter
    Dec 13, 2003
  4. replacing tags between tags

    , Sep 18, 2005, in forum: Perl Misc
    Replies:
    9
    Views:
    117
    Jürgen Exner
    Sep 19, 2005
  5. Replies:
    1
    Views:
    294
    Bart Van der Donck
    Jul 4, 2007
Loading...

Share This Page