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? Link to comment https://forums.phpfreaks.com/topic/169178-click-button-puts-text-in-an-input-field/ 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 Link to comment https://forums.phpfreaks.com/topic/169178-click-button-puts-text-in-an-input-field/#findComment-892732 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> Link to comment https://forums.phpfreaks.com/topic/169178-click-button-puts-text-in-an-input-field/#findComment-892868 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.