How to insert text into forms?

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

    How to insert text into forms?

    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

    #2
    Re: How to insert text into forms?

    Does nobody know this?

    Thanks
    Gunnar

    Gunnar Kristiansen wrote:[color=blue]
    > 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[/color]

    Comment

    • Random

      #3
      Re: How to insert text into forms?

      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:[color=blue]
      > Does nobody know this?
      >
      > Thanks
      > Gunnar
      >
      > Gunnar Kristiansen wrote:[color=green]
      > > Hi!
      > >
      > > I have a form page which I am using as a frontend for my MySql[/color][/color]
      database[color=blue][color=green]
      > > (for writing news). I do miss the functionality of a few buttons[/color][/color]
      that[color=blue][color=green]
      > > could help me insert HTML tags etc, into my main form field.[/color][/color]
      (textarea)[color=blue][color=green]
      > >
      > > 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[/color][/color]
      just[color=blue][color=green]
      > > figured that JavaScript could do such a thing...?
      > >
      > > Hoping for help!
      > >
      > > Gunnar Kristiansen
      > > Denmark[/color][/color]

      Comment

      • Gunnar Kristiansen

        #4
        Re: How to insert text into forms?

        Well, what I have now, is something like this:

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

        ....

        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:[color=blue]
        > 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:
        >[color=green]
        >>Does nobody know this?
        >>
        >>Thanks
        >>Gunnar
        >>
        >>Gunnar Kristiansen wrote:
        >>[color=darkred]
        >>>Hi!
        >>>
        >>>I have a form page which I am using as a frontend for my MySql[/color][/color]
        >
        > database
        >[color=green][color=darkred]
        >>>(for writing news). I do miss the functionality of a few buttons[/color][/color]
        >
        > that
        >[color=green][color=darkred]
        >>>could help me insert HTML tags etc, into my main form field.[/color][/color]
        >
        > (textarea)
        >[color=green][color=darkred]
        >>>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[/color][/color]
        >
        > just
        >[color=green][color=darkred]
        >>>figured that JavaScript could do such a thing...?
        >>>
        >>>Hoping for help!
        >>>
        >>>Gunnar Kristiansen
        >>>Denmark[/color][/color]
        >
        >[/color]

        Comment

        • DJ Craig

          #5
          Re: How to insert text into forms?

          You could do this with innerHTML()


          Comment

          • Random

            #6
            Re: How to insert text into forms?

            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:[color=blue]
            > Well, what I have now, is something like this:
            >
            > function insert_bold_tag ()
            > {
            > var tagbody = document.news.b ody.value;
            > var text = prompt("Enter the text you want in bold", "Your text...");
            > var boldtag = "<b>" + text + "</b>";
            > var tagbody = tagbody + boldtag;
            > document.news.b ody.value=tagbo dy;
            > }
            >
            > ...
            >
            > 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:[color=green]
            > > 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:
            > >[color=darkred]
            > >>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[/color]
            > >
            > > database
            > >[color=darkred]
            > >>>(for writing news). I do miss the functionality of a few buttons[/color]
            > >
            > > that
            > >[color=darkred]
            > >>>could help me insert HTML tags etc, into my main form field.[/color]
            > >
            > > (textarea)
            > >[color=darkred]
            > >>>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[/color]
            > >
            > > just
            > >[color=darkred]
            > >>>figured that JavaScript could do such a thing...?
            > >>>
            > >>>Hoping for help!
            > >>>
            > >>>Gunnar Kristiansen
            > >>>Denmark[/color]
            > >
            > >[/color][/color]

            Comment

            Working...