Why does textarea.value= not work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sandy Tipper

    Why does textarea.value= not work

    I have never had a textarea content change, in any browser.
    On several different projects.
    With javascript enabled (other stuff works.)
    I have read lots, and everyone says it should work.
    Can anyone tell my what's wrong with the following code?
    (I was trying to create a simple demo example.
    The alerts are there just to help find out where it fails.
    The onClick isn't even getting executed, even though
    I get it to work elsewhere.)
    ------ textarea.htm ---------
    <html>
    <head>
    <script type="text/javascript">
    <--
    function fillit(obj) {
    alert('fillit called');
    var x = obj.form.bigbox ;
    alert('The big box had: ' + x.value);
    x.value = 'Some new text';
    alert('The big box should have some new text in it.');
    return false;
    }
    //-->
    </script>
    </head>
    <body>
    <form id="myform" name="myform" action="textare a.htm" method="post">
    <textarea id="bigbox" name="bigbox" rows="5" cols="25">Origi nal
    text</textarea>
    <input type="submit" id="doit" name="doit" value="Change the text"
    onClick="return fillit(this);">
    </form>
    </body>
    </html>


  • Lee

    #2
    Re: Why does textarea.value= not work

    Sandy Tipper said:
    >
    >I have never had a textarea content change, in any browser.
    >On several different projects.
    >With javascript enabled (other stuff works.)
    >I have read lots, and everyone says it should work.
    >Can anyone tell my what's wrong with the following code?
    >(I was trying to create a simple demo example.
    >The alerts are there just to help find out where it fails.
    >The onClick isn't even getting executed, even though
    >I get it to work elsewhere.)
    >------ textarea.htm ---------
    ><html>
    ><head>
    ><script type="text/javascript">
    ><--
    >function fillit(obj) {
    alert('fillit called');
    var x = obj.form.bigbox ;
    alert('The big box had: ' + x.value);
    x.value = 'Some new text';
    alert('The big box should have some new text in it.');
    return false;
    >}
    >//-->
    ></script>
    ></head>
    ><body>
    ><form id="myform" name="myform" action="textare a.htm" method="post">
    ><textarea id="bigbox" name="bigbox" rows="5" cols="25">Origi nal
    >text</textarea>
    ><input type="submit" id="doit" name="doit" value="Change the text"
    >onClick="retur n fillit(this);">
    ></form>
    ></body>
    ></html>
    Don't use in input of type "submit" unless you're submitting
    the form, and don't use SGML comments around script:

    <html>
    <head>
    <script type="text/javascript">
    function fillit(obj) {
    alert('fillit called');
    var x = obj.form.bigbox ;
    alert('The big box had: ' + x.value);
    x.value = 'Some new text';
    alert('The big box should have some new text in it.');
    return false;
    }
    </script>
    </head>
    <body>
    <form id="myform" name="myform" action="textare a.htm" method="post">
    <textarea id="bigbox" name="bigbox" rows="5" cols="25">Origi nal
    text</textarea>
    <input type="button" id="doit" name="doit" value="Change the text"
    onClick="return fillit(this);">
    </form>
    </body>
    </html>


    --

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: Why does textarea.value= not work

      Sandy Tipper wrote:
      <script type="text/javascript">
      <--
      ^^^
      There is a syntax error; `<' and `--' are operators. If you had avoided the
      nonsensical attempt of pseudo-commenting out `script' element content with
      `<!-- ... //-->' in the first place, you would not have fallen victim to
      this error. That said, simple debugging would have revealed it:



      Markup validation will reveal more problems with your code:

      W3C's easy-to-use markup validation service, based on SGML and XML parsers.



      PointedEars
      --
      var bugRiddenCrashP ronePieceOfJunk = (
      navigator.userA gent.indexOf('M SIE 5') != -1
      && navigator.userA gent.indexOf('M ac') != -1
      ) // Plone, register_functi on.js:16

      Comment

      • Sandy Tipper

        #4
        Re: Why does textarea.value= not work

        "Thomas 'PointedEars' Lahn" <PointedEars@we b.dewrote in message
        news:47E6E28C.3 050504@PointedE ars.de...
        Sandy Tipper wrote:
        ><script type="text/javascript">
        ><--
        ^^^
        There is a syntax error; `<' and `--' are operators. If you had avoided
        the
        nonsensical attempt of pseudo-commenting out `script' element content with
        `<!-- ... //-->' in the first place, you would not have fallen victim to
        this error. That said, simple debugging would have revealed it:

        Markup validation will reveal more problems with your code:
        W3C's easy-to-use markup validation service, based on SGML and XML parsers.

        >
        PointedEars
        --
        var bugRiddenCrashP ronePieceOfJunk = (
        navigator.userA gent.indexOf('M SIE 5') != -1
        && navigator.userA gent.indexOf('M ac') != -1
        ) // Plone, register_functi on.js:16
        No need to be sarcastic. Especially when you're on thin ice.
        The comments vare recommended practice to prevent misunderstandin g
        by old browsers who don't recognoze the <scripttag. See:
        W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.

        HJowever, I know there are problems with the code,
        that;s why I asked for help.
        My debugger doidn't see anthing wrong.with the generated
        html page, but I didn't know to use the java cnsole.
        So now I know something is wrong, but don't know what.
        (I used a "button" instead of "submit", not difference.


        Comment

        • sheldonlg

          #5
          Re: Why does textarea.value= not work

          Sandy Tipper wrote:
          I have never had a textarea content change, in any browser.
          On several different projects.
          With javascript enabled (other stuff works.)
          I have read lots, and everyone says it should work.
          Can anyone tell my what's wrong with the following code?
          (I was trying to create a simple demo example.
          The alerts are there just to help find out where it fails.
          The onClick isn't even getting executed, even though
          I get it to work elsewhere.)
          ------ textarea.htm ---------
          <html>
          <head>
          <script type="text/javascript">
          <--
          function fillit(obj) {
          alert('fillit called');
          var x = obj.form.bigbox ;
          alert('The big box had: ' + x.value);
          x.value = 'Some new text';
          alert('The big box should have some new text in it.');
          return false;
          }
          //-->
          </script>
          </head>
          <body>
          <form id="myform" name="myform" action="textare a.htm" method="post">
          <textarea id="bigbox" name="bigbox" rows="5" cols="25">Origi nal
          text</textarea>
          <input type="submit" id="doit" name="doit" value="Change the text"
          onClick="return fillit(this);">
          </form>
          </body>
          </html>
          I believe (but am not 100% positive) that you need textarea.innerH TML


          Comment

          • Giacomo Boffi

            #6
            Re: Why does textarea.value= not work

            Thomas 'PointedEars' Lahn <PointedEars@we b.dewrites:
            [...] they should refrain from using W3School as Web development
            reference, which has been proven wrong or misleading so often
            does anybody care reposting some good, up-to-date tutorial reference
            for yet another newcomer?

            thank you in advance,
            g
            --
            E ti esorto a prendere in considerazione entrambe le fonti perché il
            mio parere è che, molto spesso, prendere solo quelle che facciano
            riferimento ad una parte in gioco, non aiuti ad avere un quadro
            obiettivo della situazione. -- LDA, in ISC

            Comment

            • Thomas 'PointedEars' Lahn

              #7
              Re: Why does textarea.value= not work

              Giacomo Boffi wrote:
              Thomas 'PointedEars' Lahn <PointedEars@we b.dewrites:
              >[...] they should refrain from using W3School as Web development
              >reference, which has been proven wrong or misleading so often
              >
              does anybody care reposting some good, up-to-date tutorial reference
              for yet another newcomer?
              Because Web development is a wide field, that would depend on the subject
              you are exactly interested in. For example, in this almost two months old
              subthread you have posted a followup in, the subject was whether it was
              necessary and a Good Thing to pseudo-comment out `script' element content.

              Therefore, I suggest you subscribe to this newsgroup and the newsgroups in
              the comp.infosystem s.www.authoring.* hierarchy, and check for new postings
              regularly as the discussions in the technical Usenet newsgroups are without
              doubt the most up-to-date and most factually correct tutorial you can get on
              Web development (if anyone posts nonsense, it it very likely that someone
              else will correct it and so on). It is not necessarily easy to understand
              for a newcomer, but I think you will adapt and learn like we all still do.
              thank you in advance,
              You are welcome.


              PointedEars
              --
              var bugRiddenCrashP ronePieceOfJunk = (
              navigator.userA gent.indexOf('M SIE 5') != -1
              && navigator.userA gent.indexOf('M ac') != -1
              ) // Plone, register_functi on.js:16

              Comment

              • Giacomo Boffi

                #8
                Re: Why does textarea.value= not work

                Thomas 'PointedEars' Lahn <PointedEars@we b.dewrites:
                Giacomo Boffi wrote:
                >Thomas 'PointedEars' Lahn <PointedEars@we b.dewrites:
                >>[...] they should refrain from using W3School as Web development
                >>reference, which has been proven wrong or misleading so often
                >>
                >does anybody care reposting some good, up-to-date tutorial
                >reference for yet another newcomer?
                >
                Because Web development is a wide field, that would depend on the
                subject you are exactly interested in. For example, in this almost
                two months old subthread you have posted a followup in, the subject
                was whether it was necessary and a Good Thing to pseudo-comment out
                `script' element content.
                >
                Therefore, I suggest you subscribe to this newsgroup and the
                newsgroups in the comp.infosystem s.www.authoring.* hierarchy, and
                check for new postings regularly as the discussions in the technical
                Usenet newsgroups are without doubt the most up-to-date and most
                factually correct tutorial you can get on Web development (if anyone
                posts nonsense, it it very likely that someone else will correct it
                and so on). It is not necessarily easy to understand for a
                newcomer, but I think you will adapt and learn like we all still do.
                thank you Thomas, yours is an ambitious, well conceived grand plan,
                but it's oversized with respect to my modest request of a reference to
                an up to date tutorial for javascript (site or book), taking into
                account that i'm only a curious man, not a future web developer

                en passant, i must remark that c.l.javascript' s faq mentions just
                only one tutorial, w3school's one...

                again, thank you
                g
                --
                "It will be rain tonight."
                "Let it come down."

                Comment

                • Rich Grise

                  #9
                  Re: Why does textarea.value= not work

                  On Thu, 22 May 2008 21:19:35 +0200, Giacomo Boffi wrote:
                  en passant, i must remark that c.l.javascript' s faq mentions just
                  only one tutorial, w3school's one...

                  turns up "about 237,000" hits.

                  Good Luck!
                  Rich

                  Comment

                  Working...