View Full Version : Dynamically adding text box?

07-06-2011, 06:35 PM
The code below gives the X and Y coordinates of the curser when the mouse is clicked, if it is clicked again the new coordinates are shown. How can I change the code to show the new coordinates in a new box. Id like to show multiple text boxes with new coordinates in each one.
Any help will be greatly appreciated.

<form name="Show">
Coordinates<input type="text" name="coords" value="" size="12"><br>
<script language="JavaScript1.2">
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onclick = getMouseXY;
var tempX = 0;
var tempY = 0;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
else { // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}
var coords ="X- "+tempX +" Y- "+ tempY;
document.Show.coords.value = coords;
return true;