Online Shopping : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 52 people (23%) answered Yes
Recently 2 of 10 people (20%) answered Yes

Entry

How to get the LINE and COLUMN of the cursor in a TEXTAREA by press a button?

Apr 4th, 2008 20:59
ha mo, Colin Fraser, Fernando Torres,


Simply, you cannot get the column and line location, but you can get the 
mouse co-ordinates on the screen. Try this. 
<html>
 <head>
 <script language="JavaScript"><!-- //hide from older browsers
//Determine the browser, naming which event and registering the event 
handler 
 if (navigator.appName == 'Netscape') {
     document.captureEvents(Event.MOUSEMOVE);
     document.onmousemove = nnPointerPosn;            
 }
//getting the coordinates of the pointer in Netscape, defining the the 
event handler
 function nnPointerPosn(a) {
     if (a.screenX != document.pointxy.xposn.value && a.screenY != 
document.pointxy.yposn.value) {
         document.pointxy.xposn.value = a.screenX;
         document.pointxy.yposn.value = a.screenY;
     } 
 }
 function iePointerPosn() {
     if (window.event.x != document.pointxy.xposn.value && 
window.event.y != document.pointxy.yposn.value) {
         document.pointxy.xposn.value = window.event.x;
         document.pointxy.yposn.value = window.event.y;
     }
 }
 //-->
</script>
 </head>
 <body onMousemove="iePointerPosn()">
 <form name="pointxy">
 X posn: <input type="text" name="xposn" size="5"> Y posn: <input 
type="text" name="yposn" size="5">
 </form>
 </body>
 </html>
This only works in NN and IE I have no idea about any other browser, I 
have not used a Mac or Unix versions of these programs, but this code 
should work on them.  Other browsers are not even considered here, so I 
am not sure if this will work on them. This code is not guarranteed, but 
it works on my pc.  
Please note that the nn and ie versions handle the pointer differently, 
so different versions of the same script are used. The iePointerMove 
function is called in the body tag. 
As far as your question is concerned, this is, of course, absolutely 
useless. You cannot hard code a response to the pointer position in a 
textarea, simply because different screen resolutions will place the  
pointer in different positions on the screen in the same textarea. But 
you can get the function to activate and do whatever you want it to do 
if you were to use an onMouseOver event.
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com