homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Inserting formats etc. into a form field using javascript.
Like a picture, when clicked puts <B></B> into the field.

10+ Year Member

Msg#: 3298 posted 1:15 am on Mar 4, 2005 (gmt 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.




10+ Year Member

Msg#: 3298 posted 7:53 am on Mar 4, 2005 (gmt 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

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved