mike12255 Posted September 4, 2009 Share Posted September 4, 2009 so im trying to get the text the user selects and add bold tags around them problem is my button dosnt seem to work, can anyone figure out why? <html> <head> <script language="javascript" type="text/javascript"> function ShowSelection() { var textComponent = document.getElementById('outputtext'); var selectedText; // IE version if (document.selection != undefined) { textComponent.focus(); var sel = document.selection.createRange(); selectedText = sel.text; document.myform.outputtext.value += "[b]" + selectedText + "[/b]"; } // Mozilla version else if (textComponent.selectionStart != undefined) { var startPos = textComponent.selectionStart; var endPos = textComponent.selectionEnd; selectedText = textComponent.value.substring(startPos, endPos) document.myform.outputtext.value += "[b]" + selectedText + "[/b]"; } // alert("You selected: " + selectedText); } </script> <form name="myform"> <input type="button" value="Option One" onClick="addtext1();"> <input type="button" value="Bold" onClick="ShowSelection();"> <textarea name="outputtext" cols="30" rows="25">Dear </textarea> </form> <!--next--> </body> </html> Quote Link to comment Share on other sites More sharing options...
cbolson Posted September 5, 2009 Share Posted September 5, 2009 Hi, not sure that it is the only problem with the script, but you are defining the textComponent by the id, however this is not defined. var textComponent = document.getElementById('outputtext'); For your textarea you have nly goiven it a name, if you want to use getElementById() you need to define the id attribute as well. <textarea id="outputtext" name="outputtext" cols="30" rows="25">Dear </textarea> Hope this helps you on your way Chris Quote Link to comment Share on other sites More sharing options...
mike12255 Posted September 6, 2009 Author Share Posted September 6, 2009 sadly i always make small little mistakes like that but cant catch them other then that my script does as i wish, thanks for catching the error mate 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.