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! Quote Link to comment Share on other sites More sharing options...
waynew Posted July 16, 2008 Share Posted July 16, 2008 PHP Freaks Forums > PHP > PHP Help Quote Link to comment 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> Quote Link to comment 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 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.