Canman2005 Posted November 28, 2008 Share Posted November 28, 2008 Hi all I have a form button which looks like <input type="image" src="images/longbar.gif" width="400" height="30" What I want to try and do is to display (as HTML text) above this button what position the mouse is within the button, so having a number chart going from 1.0 1.1 1.2 .... upto...... 9.8 9.9 10.0 So if someone put their mouse in the middle of this button, it would display 5.0 and if they place it at a 1/4 of the way along, it woud display 2.5 and so on. Is this possible? Can anyone help me? I'm a total ZERO when it comes to JScripting, so could really do with a hand. Thanks very very very much Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 28, 2008 Share Posted November 28, 2008 try using clientX and clientY on the event object: http://www.w3schools.com/htmldom/dom_obj_event.asp that should give you X/Y coordinates in pixels. then just calculate your scale using the image's width/height Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted November 28, 2008 Author Share Posted November 28, 2008 thanks, have had a quick look and it doesnt really make much sense, I am not a javascript coder. any other help and advice would also be appricated thanks Quote Link to comment Share on other sites More sharing options...
Canman2005 Posted November 28, 2008 Author Share Posted November 28, 2008 Okay, I have managed to track down and mod a script, it's <script type="text/javascript"> var posx; function getMouse(e){ posx=0; var ev=(!e)?window.event:e;//IE:Moz if (ev.pageX){//Moz posx=ev.pageX+window.pageXOffset; } else if(ev.clientX){//IE posx=ev.clientX+document.body.scrollLeft; } else{return false}//old browsers document.getElementById('myspan').firstChild.data='X='+posx; } document.onmousemove=getMouse </script> <span id="myspan"> </span> This seems to give the X coordinates, but I am having problems doing two things; 1: Attaching it to a form button, so that it only read the X coordinates on that button 2: Also, if you move you mouse quickly from right to left, rather than X coordinate resetting back to 0, it seems to stay on higher numbers, for example, I moved the mouse very fast from right to left and it went from a X coordinate count on the far right of 987 to 123 when it was as far left as it could be. Any reason for that? Any help would be appricated everyone 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.