GateKeeper
09-08-2002, 11:55 PM
okay, let me lay the foundation for this problem. . .
I have a rather large image being displayed on the page and I am trying to use a script to determine the distance between two points on that image through mouse clicks. A regular mouse click sets the origin point and a shift-mousclick sets the destination point. Now, on general terms, I have the script working, however, I am trying to use a do/while statement to keep the distance calculation from being preformed until both points have been selected. The problem seems to be arising from the while portion of the statement. It seems to be freezing up the browser instead of going to the calculation function.
Here is the script, if anyone can tell me what I have done wrong, I would appreciate it.
<script language="javascript">
var dxcoord = 0
var dycoord = 0
var oxcoord = 0
var oycoord = 0
var dist = 0
function getpoints()
{
do
{
if (window.event.shiftKey == true)
{
dxcoord=window.event.offsetX
dycoord=window.event.offsetY
}
else
{
oxcoord=window.event.offsetX
oycoord=window.event.offsetY
}
}
while (dxcoord == 0 || dycoord == 0 || oxcoord == 0 || oycoord == 0)
finddist()
}
function finddist()
{
dist=Math.round(Math.sqrt(Math.pow((oxcoord-dxcoord),2)-Math.pow((oycoord-dycoord),2)))
display()
}
function display()
{
document.write('The distance between point '+oxcoord+','+oycoord+' and point '+dxcoord+','+dycoord+' is '+dist+' pixels')
}
</script>
I have a rather large image being displayed on the page and I am trying to use a script to determine the distance between two points on that image through mouse clicks. A regular mouse click sets the origin point and a shift-mousclick sets the destination point. Now, on general terms, I have the script working, however, I am trying to use a do/while statement to keep the distance calculation from being preformed until both points have been selected. The problem seems to be arising from the while portion of the statement. It seems to be freezing up the browser instead of going to the calculation function.
Here is the script, if anyone can tell me what I have done wrong, I would appreciate it.
<script language="javascript">
var dxcoord = 0
var dycoord = 0
var oxcoord = 0
var oycoord = 0
var dist = 0
function getpoints()
{
do
{
if (window.event.shiftKey == true)
{
dxcoord=window.event.offsetX
dycoord=window.event.offsetY
}
else
{
oxcoord=window.event.offsetX
oycoord=window.event.offsetY
}
}
while (dxcoord == 0 || dycoord == 0 || oxcoord == 0 || oycoord == 0)
finddist()
}
function finddist()
{
dist=Math.round(Math.sqrt(Math.pow((oxcoord-dxcoord),2)-Math.pow((oycoord-dycoord),2)))
display()
}
function display()
{
document.write('The distance between point '+oxcoord+','+oycoord+' and point '+dxcoord+','+dycoord+' is '+dist+' pixels')
}
</script>