Well, thanks to a user user on this site, I was able to log some data from a JavaScript function into an html table. Now I have another question to ask. How can I run the function multiple times while the page is loading and log the output from that one function into the same html table? Because my code as of now only runs and logs the output of the function once, and when I refresh the page I lose the numbers which were previously generated. I want to be able to run the function say 10 times and display that on the html table. Your help would be greatly appreciated.
<html>
<head>
</head>
<body>
<script type="text/javascript" language="javascript">
R = 10;
theta = Math.random() * 2 * Math.PI;
r1 = Math.random() * R;
r2 = R + (Math.random() * 100);
ray = r1 + (Math.random() * (r2 - r1));
point = [ray*Math.cos(theta), ray*Math.sin(theta)];
var distance = function(x1, y1, rad, x2, y2) {
return (Math.sqrt(Math.pow((y2 - y1), 2) + Math.pow((x2 - x1), 2))) - rad;
};
</script>
<div>
<table border="1">
<th>X Center</th>
<th>Y Center</th>
<th>r1</th>
<th>r2</th>
<th>X Random</th>
<th>Y Random</th>
<th>Distance</th>
<tr>
<td><input type="text" id="x center"/></td>
<td><input type="text" id="y center"/></td>
<td><input type="text" id="r1"/></td>
<td><input type="text" id="r2"/></td>
<td><input type="text" id="x random"/></td>
<td><input type="text" id="y random"/></td>
<td><input type="text" id="displacement"/></td>
</tr>
</table>
<script>
document.getElementById("x center").value = 0;
document.getElementById("y center").value = 0;
document.getElementById("r1").value = r1;
document.getElementById("r2").value = r2;
document.getElementById("x random").value = point[0];
document.getElementById("y random").value = point[1];
document.getElementById("displacement").value = distance(0,0,R,point[0], point[1]);
</script>
</div>
</body>
</html>
tr
with all thetd
s to the table.