insert javascrpt into textarea?

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

    insert javascrpt into textarea?

    i have a translator-program for the robbers language.

    i want the user to input into the topwindow and then display the
    encryption or decryption in the bottom window.

    i am currently trying to do this via a python/webpy webapp but been
    told it can be done with javascript.

    how would i do this? i couldnt figure it out from the w3schools
    tutorial.
    and can i have a javascript to call another file? or i have to do the
    translation in the html-file below? it could get very cluttery...

    <html>
    <body bgcolor="orange ">

    <center>
    <h1><p><b>Robbe r's language encrypter/decrypter!</b></p></h1>

    <form method=post>
    <p>
    <select name="encdec">
    <option value="encrypt" >encrypt</option>
    <option value="decrypt" >decrypt</option>
    </select>
    </p>
    <textarea name="enc" rows="10" cols="50">
    </textarea>
    <p>
    <input type="submit" value="submit" /><br />
    </p>
    </form>

    <form method=post>
    <textarea name="answer" rows="10" cols="50">

    </textarea>
    </form>

    </center>
    </body>
    </html>
  • Thomas 'PointedEars' Lahn

    #2
    Re: insert javascrpt into textarea?

    globalrev wrote:
    i have a translator-program for the robbers language.
    Your Shift key is malfunctioning.
    i want the user to input into the topwindow and then display the
    encryption or decryption in the bottom window.
    >
    i am currently trying to do this via a python/webpy webapp but been
    told it can be done with javascript.
    >
    how would i do this? i couldnt figure it out from the w3schools
    tutorial.
    That is unsurprising, as the W3Schools people apparently don't know HTML
    themselves. Avoid this site, it is not suitable as Web development reference.
    and can i have a javascript to call another file? or i have to do the
    translation in the html-file below? it could get very cluttery...
    What I had to read below is very far from being a "html-file".
    <html>
    <body bgcolor="orange ">
    `orange' is not a valid value for the deprecated `bgcolor' attribute.


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

    <center>
    CSS2 turns 10 tomorrow.


    <h1><p><b>Robbe r's language encrypter/decrypter!</b></p></h1>
    Not Valid, the `p' element must not be contained in the `h1' element.


    <form method=post>
    Not Valid, the `action' attribute is required.


    <p>
    Semantically wrong element, we are not talking paragraphs of text here. Use
    `div' if you must.



    <select name="encdec">
    You should set the `size' attribute, too.


    <option value="encrypt" >encrypt</option>
    <option value="decrypt" >decrypt</option>
    </select>
    </p>
    <textarea name="enc" rows="10" cols="50">
    </textarea>
    <p>
    <input type="submit" value="submit" /><br />
    You don't want to use XHTML.



    </p>
    </form>
    >
    <form method=post>
    See above.
    <textarea name="answer" rows="10" cols="50">
    >
    </textarea>
    </form>
    You don't want to submit this form's information, so you don't need a form
    element here.
    </center>
    </body>
    </html>
    As for your question, you can achieve optional client-side operation with

    <form action="..." onsubmit="retur n handleSubmit(th is)">
    <script type="text/javascript">
    function handleSubmit()
    {
    ...

    // if successful
    return false;
    }
    </script>
    </form>

    But I strongly suggest you learn HTML first.


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann

    Comment

    • globalrev

      #3
      Re: insert javascrpt into textarea?

      As for your question, you can achieve optional client-side operation with
      >
      <form action="..." onsubmit="retur n handleSubmit(th is)">
      <script type="text/javascript">
      function handleSubmit()
      {
      ...
      >
      // if successful
      return false;
      }
      </script>
      </form>
      >
      But I strongly suggest you learn HTML first.
      >
      ty i know its not vaied html but i just threw it up quickly to learn
      to handle this type of interaction.

      where should the script be inserted?


      id i do this, but want the script to write into the textarea instead,
      how do i do that?


      <html>

      <script type="text/javascript">
      function myfunction()
      {
      alert("HELLO");
      }
      </script>

      <body>
      <center>

      <h1><p style="font-family:times new roman;color:ora nge">
      <b>Robber's language encrypter/decrypter!</b>
      </p></h1>

      <p>
      <select name="encdec">
      <option value="encrypt" >encrypt</option>
      <option value="decrypt" >decrypt</option>
      </select>
      </p>

      <textarea name="enc" rows="10" cols="50">
      </textarea>
      s
      <form>
      <input type="button"
      onclick="myfunc tion()"
      value="submit">
      </form>

      </center>
      </body>
      </html>

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: insert javascrpt into textarea?

        globalrev wrote:
        >As for your question, you can achieve optional client-side operation with
        >>
        > <form action="..." onsubmit="retur n handleSubmit(th is)">
        > <script type="text/javascript">
        > function handleSubmit()
        > {
        > ...
        >>
        > // if successful
        > return false;
        > }
        > </script>
        > </form>
        >>
        >But I strongly suggest you learn HTML first.
        >>
        >
        ty i know its not vaied html but i just threw it up quickly to learn
        to handle this type of interaction.
        You cannot expect invalid content to work; especially you cannot expect DOM
        scripting to work within and on invalid markup.


        where should the script be inserted?
        I wrote that already.
        id i do this, but want the script to write into the textarea instead,
        how do i do that?
        Please read <http://jibbering.com/faq/>. All of it, especially the
        introductory sections and the material referenced there.
        <html>
        >
        <script type="text/javascript">
        function myfunction()
        {
        alert("HELLO");
        }
        </script>
        It is still not Valid. The DOCTYPE declaration is missing, and while
        the start and end tags for the `head' element are optional in HTML 4.01
        Transitional, the `title' element within the `head' element is not.

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

        <body>
        <center>
        It is still deprecated (and is invalid with HTML 4.01 Strict).
        <h1><p style="font-family:times new roman;color:ora nge">
        The last item of a comma-separated `font-family' value should be a generic
        font family (here: `serif') --




        PointedEars
        --
        Anyone who slaps a 'this page is best viewed with Browser X' label on
        a Web page appears to be yearning for the bad old days, before the Web,
        when you had very little chance of reading a document written on another
        computer, another word processor, or another network. -- Tim Berners-Lee

        Comment

        • globalrev

          #5
          Re: insert javascrpt into textarea?

          ok now i think it is, is there a site that can validate a htmlpage run
          on my own computer(not a server or webhotel)?

          so now if it is ok, how do i insert text upon submit into the textarea
          or in another textarea below the now visible one?


          also, how can i center the textarea vertically?


          <html>
          <head>
          <title>robber 's language</title>
          <style type="text/css">
          <!--
          body {
          margin: 0px;
          padding: 0px;
          }
          #header {
          background: #FDD017;
          width: 100%;
          height: 10%;
          font-size: xx-large;
          text-align: center;
          }
          #content {
          background: white;
          float: right;
          width: 100%;
          height: 90%;
          text-align: center;
          }
          a:link {color: black; }
          a:visited {color: white; }
          a:hover {color: black; }
          a:active {color: black; }
          -->
          </style>
          </head>
          <body>


          <script type="text/javascript">
          function myfunction()
          {
          alert("HELLO");
          }
          </script>


          <div id="header">
          <b>Robber's language encrypter/decrypter</b>
          </div>
          <div id="content">
          <textarea rows="10" cols="30">
          </textarea>


          <form>
          <input type="button"
          onclick="myfunc tion()"
          value="submit">
          </form>


          </div>
          </body>
          </html>

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: insert javascrpt into textarea?

            globalrev wrote:
            ok now i think it is,
            Is *what*?
            is there a site that can validate a htmlpage run
            on my own computer(not a server or webhotel)?
            W3C's easy-to-use markup validation service, based on SGML and XML parsers.

            so now if it is ok, how do i insert text upon submit into the textarea
            or in another textarea below the now visible one?
            Read my posting again.
            also, how can i center the textarea vertically?
            The most compatible way is to use a table cell:

            <td style="vertical-align: middle">...-</td>

            Further layout questions should be asked in the
            comp.infosystem s.www.authoring.* subhierarchy.


            PointedEars
            --
            Anyone who slaps a 'this page is best viewed with Browser X' label on
            a Web page appears to be yearning for the bad old days, before the Web,
            when you had very little chance of reading a document written on another
            computer, another word processor, or another network. -- Tim Berners-Lee

            Comment

            • globalrev

              #7
              Re: insert javascrpt into textarea?

              just want to say i really appreciate your help. just find this
              frustrating because its not really what i want to spend my time on,
              want to spend it on my translator-program and just want a simple
              working webapplication.
              i guess also its fairly trivial once you know how to do it though.

              now i have a valid strict html 4.01 document.

              how do i take the text in the textarea when i press submit, then
              transform the text and put it back in the window(or somehwere else).

              the actual transformastion ill obv do by myself but how to take it and
              send it back i need to know. there just is no clear example anywhere i
              look on how to do this which is weird since it is standard procedure
              on a lot of apps.



              <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/
              TR/html4/strict.dtd">
              <html>
              <head>
              <meta http-equiv="Content-Type" content="text/html;charset=ut f-8" >

              <title>robber 's language</title>
              <style type="text/css">
              <!--
              body {
              margin: 0px;
              padding: 0px;
              }
              #header {
              background: #FDD017;
              width: 100%;
              height: 10%;
              font-size: xx-large;
              text-align: center;
              }
              #content {
              background: white;
              float: right;
              width: 100%;
              height: 90%;
              text-align: center;
              }
              a:link {color: black; }
              a:visited {color: white; }
              a:hover {color: black; }
              a:active {color: black; }
              -->
              </style>
              </head>
              <body>

              <div id="header">
              <b>Robber's language encrypter/decrypter</b>
              </div>
              <div id="content">
              <textarea name="enc" rows="10" cols="30">
              </textarea>


              </div>
              </body>
              </html>

              Comment

              • Thomas 'PointedEars' Lahn

                #8
                Re: insert javascrpt into textarea?

                Thomas 'PointedEars' Lahn wrote:
                globalrev wrote:
                >so now if it is ok, how do i insert text upon submit into the textarea
                >or in another textarea below the now visible one?
                >
                Read my posting again.
                Especially my first followup. Obviously you will also need at least one
                input control or a submit button within the `form' element, so that the form
                can be submitted and its `submit' event created and handled by the
                `onsubmit' attribute value.


                PointedEars
                --
                Anyone who slaps a 'this page is best viewed with Browser X' label on
                a Web page appears to be yearning for the bad old days, before the Web,
                when you had very little chance of reading a document written on another
                computer, another word processor, or another network. -- Tim Berners-Lee

                Comment

                • globalrev

                  #9
                  Re: insert javascrpt into textarea?

                  On 12 Maj, 01:50, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                  wrote:
                  Thomas 'PointedEars' Lahn wrote:
                  globalrev wrote:
                  so now if it is ok, how do i insert text upon submit into the textarea
                  or in another textarea below the now visible one?
                  >
                  Read my posting again.
                  >
                  Especially my first followup. Obviously you will also need at least one
                  input control or a submit button within the `form' element, so that the form
                  can be submitted and its `submit' event created and handled by the
                  `onsubmit' attribute value.
                  >
                  PointedEars
                  --
                  Anyone who slaps a 'this page is best viewed with Browser X' label on
                  a Web page appears to be yearning for the bad old days, before the Web,
                  when you had very little chance of reading a document written on another
                  computer, another word processor, or another network. -- Tim Berners-Lee



                  and obv i dont get it since i have read that several times already.

                  Comment

                  • globalrev

                    #10
                    Re: insert javascrpt into textarea?

                    <form action="..." onsubmit="retur n handleSubmit(th is)">
                    <script type="text/javascript">
                    function handleSubmit()
                    {
                    ...

                    // if successful
                    return false;
                    }
                    </script>
                    </form>

                    should a textarea be place dinsid ehere? and a submitbutton? i dont
                    get it. seriously. call me stupid but...

                    Comment

                    • Thomas 'PointedEars' Lahn

                      #11
                      Re: insert javascrpt into textarea?

                      globalrev wrote:
                      <form action="..." onsubmit="retur n handleSubmit(th is)">
                      <script type="text/javascript">
                      function handleSubmit()
                      {
                      ...
                      >
                      // if successful
                      return false;
                      }
                      </script>
                      </form>
                      >
                      should a textarea be place dinsid ehere? and a submitbutton? i dont
                      get it. seriously. call me stupid but...
                      <form action="..." onsubmit="retur n handleSubmit(th is)">
                      <script type="text/javascript">
                      function handleSubmit(f)
                      {
                      var es = f.elements;
                      var translation = translate(es['source'].value);
                      if (translation)
                      {
                      es['target'].value = translation;
                      }
                      else
                      {
                      // handle translation error
                      }

                      return false;
                      }
                      </script>
                      <div><textare a name="source" cols="80" rows="6"></textarea></div>
                      <div><input type="submit" value="Translat e"></div>
                      <div><textare a name="target" cols="80" rows="6"></textarea></div>
                      </form>

                      Besides the fact that it must be within the `head' or `body' element, the
                      current location of the `script' element is really only my personal
                      preference: I like the script code to be near the form that it is operating on.


                      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

                      • globalrev

                        #12
                        Re: insert javascrpt into textarea?

                        On 12 Maj, 04:02, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
                        wrote:
                        globalrev wrote:
                        <form action="..." onsubmit="retur n handleSubmit(th is)">
                        <script type="text/javascript">
                        function handleSubmit()
                        {
                        ...
                        >
                        // if successful
                        return false;
                        }
                        </script>
                        </form>
                        >
                        should a textarea be place dinsid ehere? and a submitbutton? i dont
                        get it. seriously. call me stupid but...
                        >
                        <form action="..." onsubmit="retur n handleSubmit(th is)">
                        <script type="text/javascript">
                        function handleSubmit(f)
                        {
                        var es = f.elements;
                        var translation = translate(es['source'].value);
                        if (translation)
                        {
                        es['target'].value = translation;
                        }
                        else
                        {
                        // handle translation error
                        }
                        >
                        return false;
                        }
                        </script>
                        <div><textare a name="source" cols="80" rows="6"></textarea></div>
                        <div><input type="submit" value="Translat e"></div>
                        <div><textare a name="target" cols="80" rows="6"></textarea></div>
                        </form>
                        >
                        Besides the fact that it must be within the `head' or `body' element, the
                        current location of the `script' element is really only my personal
                        preference: I like the script code to be near the form that it is operating on.
                        >
                        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


                        thanks but when i write something and press translate i get handed to
                        another site. it doesnt write into the second textarea.
                        i understand the code but dont see how to change it. tried Translate
                        to translate in case it is case sensitive and to put
                        es['target'].value = translation; in the else in case it was just
                        wrong boolean logic.

                        but it always redirects to new "not found".

                        Comment

                        • Thomas 'PointedEars' Lahn

                          #13
                          Re: insert javascrpt into textarea?

                          [snipped attribution novel]

                          globalrev wrote:
                          Thomas 'PointedEars' Lahn wrote:
                          > <form action="..." onsubmit="retur n handleSubmit(th is)">
                          > <script type="text/javascript">
                          > function handleSubmit(f)
                          > {
                          > var es = f.elements;
                          > var translation = translate(es['source'].value);
                          > if (translation)
                          > {
                          > es['target'].value = translation;
                          > }
                          > else
                          > {
                          > // handle translation error
                          > }
                          >>
                          > return false;
                          > }
                          > </script>
                          > <div><textare a name="source" cols="80" rows="6"></textarea></div>
                          > <div><input type="submit" value="Translat e"></div>
                          > <div><textare a name="target" cols="80" rows="6"></textarea></div>
                          > </form>
                          >>
                          >Besides the fact that it must be within the `head' or `body' element, the
                          >current location of the `script' element is really only my personal
                          >preference: I like the script code to be near the form that it is operating on.
                          >[...]
                          Will you please stop full-quoting?
                          thanks but when i write something and press translate i get handed to
                          another site. it doesnt write into the second textarea.
                          That can only be because you have not copied the code as is and forgot
                          either the `return false' or the `return' before handleSubmit(.. .).
                          i understand the code [...]
                          No, you don't. I suggest you start learning for real. NOW.

                          BTW, the pronoun `I' as well as the first character of the first word of a
                          sentence is spelled with a capital letter. I think the latter applies to
                          Swedish too, doesn't it?


                          Score adjusted

                          PointedEars
                          --
                          Anyone who slaps a 'this page is best viewed with Browser X' label on
                          a Web page appears to be yearning for the bad old days, before the Web,
                          when you had very little chance of reading a document written on another
                          computer, another word processor, or another network. -- Tim Berners-Lee

                          Comment

                          • globalrev

                            #14
                            Re: insert javascrpt into textarea?

                            You are the only one that writes with capitals on the internets ;).

                            Anyway I run the site from a python-app so thats why it redirected.

                            Launching the html-site by itself it doesnt redirect but it doesnt do
                            anything either.

                            Is it supposed to put anything I write in the toparea into the bottom
                            area?

                            Comment

                            • globalrev

                              #15
                              Re: insert javascrpt into textarea?

                              i got it to work now. thanks for all your help.


                              <form action="..." onsubmit="retur n handleSubmit(th is)">
                              <script type="text/javascript">
                              function handleSubmit(f)
                              {
                              f.elements['target'].value = f.elements['source'].value;
                              }
                              </script>
                              <div><textare a name="source" cols="60" rows="10"></textarea></div>
                              <div><input type="submit" value="translat e"></div>
                              <div><textare a name="target" cols="60" rows="10"></textarea></div>
                              </form>

                              Comment

                              Working...