Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to insert text into forms?

Reply
Thread Tools

How to insert text into forms?

 
 
Gunnar Kristiansen
Guest
Posts: n/a
 
      05-23-2005
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
 
Reply With Quote
 
 
 
 
Gunnar Kristiansen
Guest
Posts: n/a
 
      05-24-2005
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

 
Reply With Quote
 
 
 
 
Random
Guest
Posts: n/a
 
      05-24-2005
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


 
Reply With Quote
 
Gunnar Kristiansen
Guest
Posts: n/a
 
      05-24-2005
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

>
>

 
Reply With Quote
 
DJ Craig
Guest
Posts: n/a
 
      05-24-2005
You could do this with innerHTML()
http://msdn.microsoft.com/library/de.../innerhtml.asp

 
Reply With Quote
 
Random
Guest
Posts: n/a
 
      05-24-2005
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

> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Parsing XML into PHP to insert into a MySQL DB impulse() XML 0 10-13-2006 03:05 PM
converting a text file into an "insert into ..." file kublaikhan55@hotmail.com Ruby 5 07-23-2006 07:35 PM
How To Insert Code With Javascript, How to insert into a div an amountof code Sergio del Amo Javascript 4 05-29-2005 02:45 AM
Tools to extract data from SQL database and convert it into XML & insert XML data into SQL databases Harry Zoroc XML 1 07-12-2004 10:10 PM



Advertisments