How to insert text into forms?

G

Gunnar Kristiansen

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
 
R

Random

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

Gunnar Kristiansen

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


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 said:
Does nobody know this?

Thanks
Gunnar


database

that

(textarea)

just
 
R

Random

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 said:
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


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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top