dadamssg Posted August 7, 2009 Share Posted August 7, 2009 how would i go about coding a javascript snippet where, like this forum, you can click a smiley and then it outputs certain characters into the textarea? Quote Link to comment Share on other sites More sharing options...
Adam Posted August 7, 2009 Share Posted August 7, 2009 Should be able to find this through a search engine. Take a look at: http://alexking.org/blog/2003/06/02/inserting-at-the-cursor-using-javascript Quote Link to comment Share on other sites More sharing options...
dadamssg Posted August 7, 2009 Author Share Posted August 7, 2009 i suck at javascript...can you show me how to work this? this is what i have...it's not doing anything though <html> <head> <script type="text/javascript"> function insertAtCursor(myField, myValue) { //IE support if (document.selection) { myField.focus(); sel = document.selection.createRange(); sel.text = myValue; } //MOZILLA/NETSCAPE support else if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); } else { myField.value += myValue; } } </script> </head> <body> <textarea name='myField' id='myField'></textarea> <button type='button'onlcick= insertAtCursor(document.formName.fieldName, 'this value'); >Click</button> </body> </html> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.