Advertisement
zzarbi

Click on part of an input field

Aug 5th, 2011
1,539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <title></title>
  4. </head>
  5. <body>
  6. <script type="text/javascript">
  7.     var tempX = 0;
  8.     var tempY = 0;
  9.  
  10.     document.onmousemove = getMouseXY;
  11.  
  12.     function getMouseXY(e) {
  13.             tempX = e.pageX;
  14.             tempY = e.pageY;
  15.  
  16.             // catch possible negative values in NS4
  17.             if (tempX < 0){tempX = 0}
  18.             if (tempY < 0){tempY = 0}
  19.  
  20.             // show the position values in the form named Show
  21.             // in the text fields named MouseX and MouseY
  22.             document.getElementById('MouseX').value = tempX;
  23.             document.getElementById('MouseY').value = tempY;
  24.             return true;
  25.     }
  26.  
  27.     function search(){
  28.             // position of input field
  29.             var distanceFromTop = 60;
  30.             var distanceFromLeft = 8;
  31.  
  32.             // size of input field
  33.             var inputWidth = 204;
  34.             var inputHeight = 20;
  35.  
  36.             // size of picture
  37.             var pictureWitdh = 20;
  38.  
  39.             // dont need to check mouse position on axis y
  40.             // because onclick event already is on input field
  41.  
  42.             // check mouse position on axis x
  43.             if(tempX > (distanceFromLeft+inputWidth-pictureWitdh)){
  44.                     alert('Did click on the right');
  45.             }
  46.     }
  47. </script>
  48. <input type="text" id="MouseX" value="0" size="4"> X<br>
  49. <input type="text" id="MouseY" value="0" size="4"> Y<br>
  50. <input type="text" id="search" onclick="search(this)" />
  51. </body>
  52. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement