MDanz Posted September 17, 2009 Share Posted September 17, 2009 this is the function i call onclick with.. <script type='text/javascript'> function changeImage(){ var newtext = "[/img]"; document.changer.reply.value += newtext; } </script> the textarea name is 'reply' it puts the image tag in the textarea.. but how do i change it so it wraps around whatever is in the textbox. Quote Link to comment Share on other sites More sharing options...
kratsg Posted September 17, 2009 Share Posted September 17, 2009 <script type='text/javascript'> function changeImage(){ var newtext = ""; document.changer.reply.value += newtext; } </script> So, this code basically adds "" (IE: nothing) to the end of whatever is in reply? I'm not quite sure where this image tag is that you seem to be talking about. *Side Note: In order to get images to wrap text, you use the align attribute. http://www.w3schools.com/HTML/tryit.asp?filename=tryhtml_image_align Quote Link to comment Share on other sites More sharing options...
MDanz Posted September 17, 2009 Author Share Posted September 17, 2009 <script type='text/javascript'> function changeImage(){ var newtext = ""; document.changer.reply.value += newtext; } </script> So, this code basically adds "" (IE: nothing) to the end of whatever is in reply? I'm not quite sure where this image tag is that you seem to be talking about. *Side Note: In order to get images to wrap text, you use the align attribute. http://www.w3schools.com/HTML/tryit.asp?filename=tryhtml_image_align oops.. the forum used the tags and displayed nothing this isn't the full code.. i'm not including the class with all the bbtags here is how the function for image tag is called with onclick=changeImage(); <script type='text/javascript'> function changeImage(){ var newtext = "<img></img>"; document.changer.reply.value += newtext; } </script> how do i change the code so it wraps the tag around the selected text.. btw reply is the id of the text area Quote Link to comment Share on other sites More sharing options...
kratsg Posted September 17, 2009 Share Posted September 17, 2009 oops.. the forum used the tags and displayed nothing this isn't the full code.. i'm not including the class with all the bbtags here is how the function for image tag is called with onclick=changeImage(); <script type='text/javascript'> function changeImage(){ var newtext = "<img></img>"; document.changer.reply.value += newtext; } </script> how do i change the code so it wraps the tag around the selected text.. btw reply is the id of the text area First things first: var reply = document.getElementById("reply"); reply.value += newtext; Use this instead, at least you won't have issues trying to reference the textarea. var text1 = "<img>"; var text2 = "</img>"; if (typeof(reply.selectionStart) != "undefined") { var begin = reply.value.substr(0, myArea.selectionStart); var selection = reply.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart); var end = reply.value.substr(myArea.selectionEnd); reply.value = begin + text1 + selection + text2 + end; } Quote Link to comment Share on other sites More sharing options...
MDanz Posted September 17, 2009 Author Share Posted September 17, 2009 i tried your code... didn't work?? can you spot what is wrong? onclick <img src='http://www.u-stack.com/img.jpg' alt='image!' onclick='changeImage()' /> function function changeImage(){ var text1 = "<img>"; var text2 = "</img>"; if (typeof(reply.selectionStart) != "undefined") { var begin = reply.value.substr(0, myArea.selectionStart); var selection = reply.value.substr(myArea.selectionStart, myArea.selectionEnd - myArea.selectionStart); var end = reply.value.substr(myArea.selectionEnd); reply.value = begin + text1 + selection + text2 + end; }} textarea <textarea name="reply" cols="118" rows="15" wrap="hard" id="reply" style="color:white; background-image:url(btalarge.jpg); border-color:#FBB917" readonly="readonly"></textarea Quote Link to comment Share on other sites More sharing options...
kratsg Posted September 18, 2009 Share Posted September 18, 2009 var text1 = "<img>"; var text2 = "</img>"; if (typeof(reply.selectionStart) != "undefined") { var begin = reply.value.substr(0, reply.selectionStart); var selection = reply.value.substr(reply.selectionStart, reply.selectionEnd - reply.selectionStart); var end = reply.value.substr(reply.selectionEnd); reply.value = begin + text1 + selection + text2 + end; } Try that. 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.