Welcome to WebmasterWorld Guest from 54.196.175.173

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.

     

isaaclloyd

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.

~Isaac~

orion_rus

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)
{myField=documetn.getElementById(elem);
if (document.selection) {
myField.focus();
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);
myField.selectionStart=startPos+Math.round((myValue.length-1)/2);
myField.selectionEnd=startPos+Math.round((myValue.length-1)/2);
myField.focus();
} 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