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)

10+ Year Member

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)

10+ Year Member

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


Featured Threads

Hot Threads This Week

Hot Threads This Month