Fsoft Posted July 16, 2008 Share Posted July 16, 2008 Hey, I want to make a simple java script What I want is to make a simple / small editor buttons. So here we go. There will be 4 HTML buttons and one text box. And the buttons will be for Bold / Italic / Center / Underline. So what I want is to have a javascript, but which if we select a particular text and click on B button, it will automatically get [b]text here[/b] I don't want users to manually do that Please help. Thanks a lot FAISAL! Link to comment https://forums.phpfreaks.com/topic/115020-simple-java-script-press-action/ Share on other sites More sharing options...
waynew Posted July 16, 2008 Share Posted July 16, 2008 PHP Freaks Forums > PHP > PHP Help Link to comment https://forums.phpfreaks.com/topic/115020-simple-java-script-press-action/#findComment-591468 Share on other sites More sharing options...
waynew Posted July 16, 2008 Share Posted July 16, 2008 Place in header: <script type="text/javascript"> <!-- function insertAtCursor(fieldID, myValue) { fieldObj = document.getElementById(fieldID); if (document.selection) { //IE support fieldObj.focus(); sel = document.selection.createRange(); sel.text = myValue; } else if (fieldObj.selectionStart || fieldObj.selectionStart == "0") { //Mozilla/Firefox/Netscape 7+ support var startText = fieldObj.value.substring(0, fieldObj.selectionStart); var endText = fieldObj.value.substring(fieldObj.selectionEnd, fieldObj.value.length); fieldObj.value = startText + myValue + endText; } else { //Unable to insert at current position - add to end of current value fieldObj.value += myValue; } } //--> </script> Sample link: <a href="#" onClick="insertAtCursor('name_of_form','[b]text here[/b]'[b]text here[/b]</a> Link to comment https://forums.phpfreaks.com/topic/115020-simple-java-script-press-action/#findComment-591472 Share on other sites More sharing options...
kenrbnsn Posted July 16, 2008 Share Posted July 16, 2008 Moving this from the PHP help section to the Javascript help section. Ken Link to comment https://forums.phpfreaks.com/topic/115020-simple-java-script-press-action/#findComment-591500 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.