Hi
Thank you very much for your help with this, your solution worked perfectly and has helped me to learn more about JavaScript, although, obviously I still have much to learn. I have made some changes which I hope have followed your example.
Moving on…
I’ve added another textbox which now gets the mouse coordinates onclick, as well as adding the default value of 100 to the second box.
My current problem is again around the addElement function; I would like to make the coordinate box read-only but leave the box with the default value editable by the user, can you point me in the right direction to do this?
Code:
<html>
<head>
<script type = "text/javascript">
var myVar = 0;
var coords=""
var coords2
document.onclick = master;
function master(e){
getMouseXY(e);
addElement();
}
var IE = document.all?true:false;
if (!IE) {
document.captureEvents(Event.MOUSEMOVE)
}
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.form1.coords.value = coords;
coords2 = document.form1.coords.value;
return true;
}
function addElement() {
var ni = document.getElementById('myDiv');
var numi = document.getElementById('theValue');
var num = (document.getElementById('theValue').value -1);
numi.value = num;
var newdiv = document.createElement('div');
var divIdName = 'my'+num+'Div';
newdiv.setAttribute('id',divIdName);
newdiv.innerHTML = "tp"+myVar+" ";//<input type='text' size = '60' name='poll_option"+num+"' onblur = 'capture(this)' value = '"+coords2+"' />"
ni.appendChild(newdiv);
var inp = document.createElement('input');
var inp2 = document.createElement('input');
inp.type='text'
inp.size = '3'
inp.className='capt'
inp.name='txtbox'+num;
inp.onblur = 'capture(this)'
inp.value = 100
inp2.type='text'
inp2.size = '14'
inp2.name='tpRad"+num+"'
inp2.value = coords2;
newdiv.appendChild(inp2);
newdiv.appendChild(inp);
myVar ++;
}
</script>
</head>
<body>
<form name="form1">
<input type="hidden" id="theValue" name="coords" value="" size="12">
<div id="myDiv"> </div>
</form>
</body>
</html>