xataku_nakusute
10-12-2003, 04:16 PM
how can i get the current position of the cursor within a textarea and use the split() function or something else to add text to where the cursor is and not to the very end of the text?
|
Click to See Complete Forum and Search --> : textarea and cursor position help xataku_nakusute 10-12-2003, 04:16 PM how can i get the current position of the cursor within a textarea and use the split() function or something else to add text to where the cursor is and not to the very end of the text? pyro 10-12-2003, 06:43 PM As far as I know, there is no DOM compatable way to do that, but here's an IE only solution: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Example</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> function addFormatting(txt) { document.myform.mytext.focus(); document.selection.createRange().text = txt+document.selection.createRange().text; } </script> </head> <body> <form name="myform"> <p><textarea name="mytext" rows="10" cols="50"></textarea><br> <input type="button" value="foo" onclick="addFormatting('foo');"></p> </form> </body> </html> xataku_nakusute 10-12-2003, 07:39 PM thank you for that solution you came up with. however, you said an ie solution...so im assuming its only worth-while for ie users....and unfortunately im trying to create this for multiple browsers.....im curious....cuz this site uses what im looking for with the buttons above the textarea that im typing in right now. are you sure theres no other way? if not, its ok. youve done more than enough for me thanx Khalid Ali 10-12-2003, 07:53 PM Originally posted by xataku_nakusute are you sure theres no other way thanx Yes there is,however, you will need to search the mozilla pages for that , then you can make use of Pyro's solution and the mozilla based solution. for at least 2 major players. pyro 10-12-2003, 08:42 PM This forums just prepends the value to the end of the textarea -- it doesn't insert the content where your cursor is. webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |