Buttero Posted February 9, 2007 Share Posted February 9, 2007 Hey, I wanna add a new button to this there is already a buttob to press for bold , and italic, i want to add one for paragraph (<p>) here is my current code: <script language="JavaScript" type="text/javascript"> <!-- // global variable for textarea and menubar (i'm lazy, what can i say?) var ta; var bar; function init() { // init global variables ta = document.getElementById("ta"); bar = document.getElementById("bar"); if(ta.selectionStart != undefined) { // has support for DOM2 Ranging in textarea ta.addEventListener("keypress", checkKey, true); // add listener bar.style.display = "block"; // unhide the sucker } } function checkKey(evt) { // debug window.status = evt.charCode; if (evt.ctrlKey != true) return; if (evt.shiftKey != true) return; // t or if(evt.charCode == 116 || evt.charCode == 84) { tag('em'); } // b or B if(evt.charCode == 66 || evt.charCode == 98) { tag('strong'); } } function tag(tag) { start = ta.selectionStart; end = ta.selectionEnd; // Split before, sel, after and insert tags in between before = (ta.value).substring(0, start); sel = (ta.value).substring(start, end); after = (ta.value).substring(end, ta.textLength); ta.value = before + "<" + tag + ">" + sel + "</" + tag + ">" + after; // focus ta.focus(); ta.selectionStart = end + 5 + (tag.length * 2); ta.selectionEnd = ta.selectionStart; } //--> </script> Link to comment https://forums.phpfreaks.com/topic/37824-adding-a-new-function/ Share on other sites More sharing options...
fenway Posted February 10, 2007 Share Posted February 10, 2007 What's the problem? Link to comment https://forums.phpfreaks.com/topic/37824-adding-a-new-function/#findComment-181225 Share on other sites More sharing options...
mainewoods Posted February 11, 2007 Share Posted February 11, 2007 add a few lines at the end of your CheckKey() function // b or B ** old code if(evt.charCode == 66 || evt.charCode == 98) { tag('strong'); } // p or P ** mark paragraph ***** if (evt.charCode == ?? || evt.charCode == ??) { //fill in the ????s tag('p'); //should make paragraph tags } Link to comment https://forums.phpfreaks.com/topic/37824-adding-a-new-function/#findComment-181675 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.