How to insert text into forms?

Discussion in 'Javascript' started by Gunnar Kristiansen, May 23, 2005.

  1. Hi!

    I have a form page which I am using as a frontend for my MySql database
    (for writing news). I do miss the functionality of a few buttons that
    could help me insert HTML tags etc, into my main form field. (textarea)

    Example:
    One button named "LINK" pop's up a windows once it's clicked. This
    windows asks for a) My URL, b) A text to be used for link-text.
    Afterwards it's all being inserted into my form field.

    How do I do stuff like that? I am not into Javascript at all, but I just
    figured that JavaScript could do such a thing...?

    Hoping for help!

    Gunnar Kristiansen
    Denmark
     
    Gunnar Kristiansen, May 23, 2005
    #1
    1. Advertising

  2. Does nobody know this?

    Thanks
    Gunnar

    Gunnar Kristiansen wrote:
    > Hi!
    >
    > I have a form page which I am using as a frontend for my MySql database
    > (for writing news). I do miss the functionality of a few buttons that
    > could help me insert HTML tags etc, into my main form field. (textarea)
    >
    > Example:
    > One button named "LINK" pop's up a windows once it's clicked. This
    > windows asks for a) My URL, b) A text to be used for link-text.
    > Afterwards it's all being inserted into my form field.
    >
    > How do I do stuff like that? I am not into Javascript at all, but I just
    > figured that JavaScript could do such a thing...?
    >
    > Hoping for help!
    >
    > Gunnar Kristiansen
    > Denmark
     
    Gunnar Kristiansen, May 24, 2005
    #2
    1. Advertising

  3. Gunnar Kristiansen

    Random Guest

    To clarify:
    You want to generate an HTML tag and, rather than putting the element
    on the page itself, insert the HTML into the value of a <textarea />?

    document.forms[ myForm ].elements[ myTextArea ].value +=
    '<a href="' + escape( myURL ) + '">' +
    myLinkText + '</a>';

    Something like that?





    Gunnar Kristiansen wrote:
    > Does nobody know this?
    >
    > Thanks
    > Gunnar
    >
    > Gunnar Kristiansen wrote:
    > > Hi!
    > >
    > > I have a form page which I am using as a frontend for my MySql

    database
    > > (for writing news). I do miss the functionality of a few buttons

    that
    > > could help me insert HTML tags etc, into my main form field.

    (textarea)
    > >
    > > Example:
    > > One button named "LINK" pop's up a windows once it's clicked. This
    > > windows asks for a) My URL, b) A text to be used for link-text.
    > > Afterwards it's all being inserted into my form field.
    > >
    > > How do I do stuff like that? I am not into Javascript at all, but I

    just
    > > figured that JavaScript could do such a thing...?
    > >
    > > Hoping for help!
    > >
    > > Gunnar Kristiansen
    > > Denmark
     
    Random, May 24, 2005
    #3
  4. Well, what I have now, is something like this:

    function insert_bold_tag()
    {
    var tagbody = document.news.body.value;
    var text = prompt("Enter the text you want in bold", "Your text...");
    var boldtag = "<b>" + text + "</b>";
    var tagbody = tagbody + boldtag;
    document.news.body.value=tagbody;
    }

    ....

    and then:

    <input type="button" name="button" value="Bold"
    onclick="insert_bold_tag()";>

    But it doesn't work in any of my browsers. Can you see whats wrong, or
    give me an example of something better?

    Thanks
    Gunnar



    Random wrote:
    > To clarify:
    > You want to generate an HTML tag and, rather than putting the element
    > on the page itself, insert the HTML into the value of a <textarea />?
    >
    > document.forms[ myForm ].elements[ myTextArea ].value +=
    > '<a href="' + escape( myURL ) + '">' +
    > myLinkText + '</a>';
    >
    > Something like that?
    >
    >
    >
    >
    >
    > Gunnar Kristiansen wrote:
    >
    >>Does nobody know this?
    >>
    >>Thanks
    >>Gunnar
    >>
    >>Gunnar Kristiansen wrote:
    >>
    >>>Hi!
    >>>
    >>>I have a form page which I am using as a frontend for my MySql

    >
    > database
    >
    >>>(for writing news). I do miss the functionality of a few buttons

    >
    > that
    >
    >>>could help me insert HTML tags etc, into my main form field.

    >
    > (textarea)
    >
    >>>Example:
    >>>One button named "LINK" pop's up a windows once it's clicked. This
    >>>windows asks for a) My URL, b) A text to be used for link-text.
    >>>Afterwards it's all being inserted into my form field.
    >>>
    >>>How do I do stuff like that? I am not into Javascript at all, but I

    >
    > just
    >
    >>>figured that JavaScript could do such a thing...?
    >>>
    >>>Hoping for help!
    >>>
    >>>Gunnar Kristiansen
    >>>Denmark

    >
    >
     
    Gunnar Kristiansen, May 24, 2005
    #4
  5. Gunnar Kristiansen

    DJ Craig Guest

    DJ Craig, May 24, 2005
    #5
  6. Gunnar Kristiansen

    Random Guest

    Worked fine for me in IE/Win32. The logic, if inefficient, is
    functional.

    Try using the document.forms and documents.forms[ myForm ].elements
    collections if you're having compatibility issues.


    p.s. do you really need the 'tagbody' variable? I'd also recommend
    checking that the value of your 'text' variable is a true value, so you
    can press 'cancel'.

    Gunnar Kristiansen wrote:
    > Well, what I have now, is something like this:
    >
    > function insert_bold_tag()
    > {
    > var tagbody = document.news.body.value;
    > var text = prompt("Enter the text you want in bold", "Your text...");
    > var boldtag = "<b>" + text + "</b>";
    > var tagbody = tagbody + boldtag;
    > document.news.body.value=tagbody;
    > }
    >
    > ...
    >
    > and then:
    >
    > <input type="button" name="button" value="Bold"
    > onclick="insert_bold_tag()";>
    >
    > But it doesn't work in any of my browsers. Can you see whats wrong, or
    > give me an example of something better?
    >
    > Thanks
    > Gunnar
    >
    >
    >
    > Random wrote:
    > > To clarify:
    > > You want to generate an HTML tag and, rather than putting the element
    > > on the page itself, insert the HTML into the value of a <textarea />?
    > >
    > > document.forms[ myForm ].elements[ myTextArea ].value +=
    > > '<a href="' + escape( myURL ) + '">' +
    > > myLinkText + '</a>';
    > >
    > > Something like that?
    > >
    > >
    > >
    > >
    > >
    > > Gunnar Kristiansen wrote:
    > >
    > >>Does nobody know this?
    > >>
    > >>Thanks
    > >>Gunnar
    > >>
    > >>Gunnar Kristiansen wrote:
    > >>
    > >>>Hi!
    > >>>
    > >>>I have a form page which I am using as a frontend for my MySql

    > >
    > > database
    > >
    > >>>(for writing news). I do miss the functionality of a few buttons

    > >
    > > that
    > >
    > >>>could help me insert HTML tags etc, into my main form field.

    > >
    > > (textarea)
    > >
    > >>>Example:
    > >>>One button named "LINK" pop's up a windows once it's clicked. This
    > >>>windows asks for a) My URL, b) A text to be used for link-text.
    > >>>Afterwards it's all being inserted into my form field.
    > >>>
    > >>>How do I do stuff like that? I am not into Javascript at all, but I

    > >
    > > just
    > >
    > >>>figured that JavaScript could do such a thing...?
    > >>>
    > >>>Hoping for help!
    > >>>
    > >>>Gunnar Kristiansen
    > >>>Denmark

    > >
    > >
     
    Random, May 24, 2005
    #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. =?Utf-8?B?ZGF2aWQ=?=

    embedded windows forms into web forms for control

    =?Utf-8?B?ZGF2aWQ=?=, Apr 7, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    5,273
    =?Utf-8?B?ZGF2aWQ=?=
    Apr 10, 2005
  2. Eric
    Replies:
    2
    Views:
    649
  3. Ian Griffiths

    INSERT INTO using HTML forms

    Ian Griffiths, Oct 26, 2003, in forum: ASP General
    Replies:
    3
    Views:
    181
  4. Replies:
    5
    Views:
    294
  5. Sergio del Amo
    Replies:
    4
    Views:
    267
Loading...

Share This Page