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

Visit PubCon.com
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.
isaaclloyd




msg:1484168
 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.

~Isaac~

 

orion_rus




msg:1484169
 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)
{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

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