Crimmm
09-14-2011, 01:32 AM
I am trying to allow the user to type in two numbers and then a multiplication table pops up below it. It works however I cannot figure out how to make the first row be 0,1,2,3,4,5..ect and same for the first column in each row going down the table. Here is my code..
<html>
<head>
<title>Untitled</title>
<script>
function f(x,y)
{
if((x < 3) || (y < 3) || (x > 10) || (y > 10)){
alert("Please enter numbers between 3 and 7")
}else{
s = "<table border = '1'>"
var total;
for (i=0; i<=x; i++){
s+= "<tr></tr>";
for (j=0; j <= y; j++){
total = i * j;
s+="<td>"+ total +"</td>"
}
}
s+="</table>"
document.getElementById("Q").innerHTML+=s
}
}
</script>
</head>
<body>
[enter a number between 3 and 10]
<form id = "form1">
<input id = "a" value = "6"> by <input id = "b" value = "8"><br>
<input type = "button" onclick = "f(a.value,b.value)" value = "Click here when ready!">
<br>
</form>
<div id = "Q"></div>
</body>
</html>
<html>
<head>
<title>Untitled</title>
<script>
function f(x,y)
{
if((x < 3) || (y < 3) || (x > 10) || (y > 10)){
alert("Please enter numbers between 3 and 7")
}else{
s = "<table border = '1'>"
var total;
for (i=0; i<=x; i++){
s+= "<tr></tr>";
for (j=0; j <= y; j++){
total = i * j;
s+="<td>"+ total +"</td>"
}
}
s+="</table>"
document.getElementById("Q").innerHTML+=s
}
}
</script>
</head>
<body>
[enter a number between 3 and 10]
<form id = "form1">
<input id = "a" value = "6"> by <input id = "b" value = "8"><br>
<input type = "button" onclick = "f(a.value,b.value)" value = "Click here when ready!">
<br>
</form>
<div id = "Q"></div>
</body>
</html>