Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Inserting formats etc. into a form field using javascript.

Like a picture, when clicked puts <B></B> into the field.

1:15 am on Mar 4, 2005 (gmt 0)

New User

10+ Year Member

joined:Feb 22, 2005
votes: 0

I am trying to make a javascript so when I click on a picture on the page (like a letter B picture) it will insert a format into the text area field. Like <b></b>
Like this:

My text...

(when icon clicked)
<B>My text...</B>

Any comments/suggestions are greatly apreciated. Thanks.


7:53 am on Mar 4, 2005 (gmt 0)

Preferred Member

10+ Year Member

joined:Oct 3, 2004
votes: 0

hmm i can show u a code which make something like so but it put's tags right before and after cursor

function addtoelement(myValue,elem)
if (document.selection) {
sel = document.selection.createRange();
sel.text = myValue;
else if (myField.selectionStart ¦¦ myField.selectionStart == '0')
startPos = myField.selectionStart;
endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;

in a body u should have
<textarea id="insert" ></textarea>
<img src='somesource' onclick=addtoelement('','insert') />

not a problem to modify this code to you situation


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members