insert javascrpt into textarea?

Discussion in 'Javascript' started by globalrev, May 11, 2008.

  1. globalrev

    globalrev Guest

    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>Robber'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>
    globalrev, May 11, 2008
    #1
    1. Advertising

  2. 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.

    http://www.w3.org/TR/REC-html40/types.html#h-6.5
    http://validator.w3.org/

    > <center>


    CSS2 turns 10 tomorrow.

    http://www.w3.org/TR/REC-html40/present/graphics.html#edef-CENTER

    > <h1><p><b>Robber's language encrypter/decrypter!</b></p></h1>


    Not Valid, the `p' element must not be contained in the `h1' element.

    http://www.w3.org/TR/REC-html40/struct/global.html#edef-H1

    > <form method=post>


    Not Valid, the `action' attribute is required.

    http://www.w3.org/TR/REC-html40/interact/forms.html#edef-FORM

    > <p>


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

    http://www.w3.org/TR/REC-html40/struct/text.html#edef-P
    http://www.w3.org/TR/REC-html40/struct/global.html#edef-DIV

    > <select name="encdec">


    You should set the `size' attribute, too.

    http://www.w3.org/TR/REC-html40/interact/forms.html#edef-SELECT

    > <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.

    http://hixie.ch/advocacy/xhtml
    http://hsivonen.iki.fi/xhtml-the-point/

    > </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="return handleSubmit(this)">
    <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
    Thomas 'PointedEars' Lahn, May 11, 2008
    #2
    1. Advertising

  3. globalrev

    globalrev Guest

    > As for your question, you can achieve optional client-side operation with
    >
    > <form action="..." onsubmit="return handleSubmit(this)">
    > <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:eek:range">
    <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="myfunction()"
    value="submit">
    </form>

    </center>
    </body>
    </html>
    globalrev, May 11, 2008
    #3
  4. globalrev wrote:
    >> As for your question, you can achieve optional client-side operation with
    >>
    >> <form action="..." onsubmit="return handleSubmit(this)">
    >> <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.

    http://diveintomark.org/archives/2003/05/05/why_we_wont_help_you

    > 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.

    http://validator.w3.org/

    > <body>
    > <center>


    It is still deprecated (and is invalid with HTML 4.01 Strict).

    > <h1><p style="font-family:times new roman;color:eek:range">


    The last item of a comma-separated `font-family' value should be a generic
    font family (here: `serif') --

    http://www.w3.org/TR/CSS2/fonts.html#propdef-font-family


    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
    Thomas 'PointedEars' Lahn, May 11, 2008
    #4
  5. globalrev

    globalrev Guest

    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="myfunction()"
    value="submit">
    </form>


    </div>
    </body>
    </html>
    globalrev, May 11, 2008
    #5
  6. 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)?


    http://validator.w3.org/#validate-by-upload

    > 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.infosystems.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
    Thomas 'PointedEars' Lahn, May 11, 2008
    #6
  7. globalrev

    globalrev Guest

    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=utf-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>
    globalrev, May 11, 2008
    #7
  8. 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
    Thomas 'PointedEars' Lahn, May 12, 2008
    #8
  9. globalrev

    globalrev Guest

    On 12 Maj, 01:50, Thomas 'PointedEars' Lahn <>
    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.
    globalrev, May 12, 2008
    #9
  10. globalrev

    globalrev Guest

    <form action="..." onsubmit="return handleSubmit(this)">
    <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...
    globalrev, May 12, 2008
    #10
  11. globalrev wrote:
    > <form action="..." onsubmit="return handleSubmit(this)">
    > <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="return handleSubmit(this)">
    <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><textarea name="source" cols="80" rows="6"></textarea></div>
    <div><input type="submit" value="Translate"></div>
    <div><textarea 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 bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
    Thomas 'PointedEars' Lahn, May 12, 2008
    #11
  12. globalrev

    globalrev Guest

    On 12 Maj, 04:02, Thomas 'PointedEars' Lahn <>
    wrote:
    > globalrev wrote:
    > > <form action="..." onsubmit="return handleSubmit(this)">
    > > <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="return handleSubmit(this)">
    > <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><textarea name="source" cols="80" rows="6"></textarea></div>
    > <div><input type="submit" value="Translate"></div>
    > <div><textarea 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 bugRiddenCrashPronePieceOfJunk = (
    > navigator.userAgent.indexOf('MSIE 5') != -1
    > && navigator.userAgent.indexOf('Mac') != -1
    > ) // Plone, register_function.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".
    globalrev, May 12, 2008
    #12
  13. [snipped attribution novel]

    globalrev wrote:
    > Thomas 'PointedEars' Lahn wrote:
    >> <form action="..." onsubmit="return handleSubmit(this)">
    >> <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><textarea name="source" cols="80" rows="6"></textarea></div>
    >> <div><input type="submit" value="Translate"></div>
    >> <div><textarea 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
    Thomas 'PointedEars' Lahn, May 12, 2008
    #13
  14. globalrev

    globalrev Guest

    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?
    globalrev, May 12, 2008
    #14
  15. globalrev

    globalrev Guest

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


    <form action="..." onsubmit="return handleSubmit(this)">
    <script type="text/javascript">
    function handleSubmit(f)
    {
    f.elements['target'].value = f.elements['source'].value;
    }
    </script>
    <div><textarea name="source" cols="60" rows="10"></textarea></div>
    <div><input type="submit" value="translate"></div>
    <div><textarea name="target" cols="60" rows="10"></textarea></div>
    </form>
    globalrev, May 12, 2008
    #15
  16. In comp.lang.javascript message <4eb861ff-00ac-44d5-b12d-5aec8a556a8e@p2
    5g2000hsf.googlegroups.com>, Sun, 11 May 2008 15:04:16, globalrev
    <> posted:

    >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)?


    Download the free browser Opera, and Ctrl-Alt-V will submit the current
    page to a W3 validator, over the net.

    If you mean, however, that you want to validate your page without using
    the Net at the time, then W3's TIDY can be used in check-only fashion.
    Whether or not it is a full validator, it can certainly detect many
    errors.

    For more, see in my <URL:http://www.merlyn.demon.co.uk/www-use2.htm>; it
    needs updating, but, as far as I can immediately see, it's satisfactory
    as far as it goes.

    <FAQENTRY>
    Sec 2.3 needs something on the need for valid HTML.
    Section 5 needs something about maintainers who have ceased maintaining.

    It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
    news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
    <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
    Dr J R Stockton, May 12, 2008
    #16
    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. Rob Meade
    Replies:
    7
    Views:
    296
    Eliyahu Goldin
    Mar 18, 2007
  2. =?Utf-8?B?ZXJpYw==?=

    Javascrpt and User Controls. Help!

    =?Utf-8?B?ZXJpYw==?=, Nov 8, 2007, in forum: ASP .Net
    Replies:
    6
    Views:
    351
    Kevin Spencer
    Nov 9, 2007
  3. Rick Csucsai

    how to insert text into middle of textarea

    Rick Csucsai, Jun 21, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    261
    Harolds
    Jun 24, 2005
  4. Howard Kaikow
    Replies:
    4
    Views:
    81
    Stewart Gordon
    Oct 12, 2004
  5. Grzegorz ¦lusarek

    javascrpt IDE

    Grzegorz ¦lusarek, May 11, 2006, in forum: Javascript
    Replies:
    3
    Views:
    92
    Thomas 'PointedEars' Lahn
    May 20, 2006
Loading...

Share This Page