我有代码,当我单击提交按钮时,我需要在其中获取一个随机数。随机数应显示在同一页面的另一个文本框中。
这是我的代码:
<html>
<head>
<script type="text/javascript">
function randomnumber(num1, num2)
{
num1 = parseInt(num1);
num2 = parseInt(num2);
if(num1 >= num2)
{
alert("Number 2 should be greater than Number 1");
}
else
{
var generator = Math.random()*(num2-num1);
generator = Math.round(num1+generator);
document.test.result.value = generator;
document.getElementById("p1").innerHTML=generator;
}
}
</script>
</head>
<body>
<form name="test" onsubmit = "return randomnumber(num1,num2)" >
<table>
<tr>
<td>
<input type="text" name="num1" size ="35" maxlength= "25">
</td>
<td>
<input type="text" name="num2" size ="35" maxlength= "25">
</td>
<td>
<input type="text" name="p1" value = "" size ="35" maxlength= "25">
</td>
<td>
<input type="submit" name="submit" value"generate">
</td>
</tr>
</table>
</form>
</body>
</html>
随机数在脚本中的变量“生成器”中生成。我需要获取此文本字段中的值。
<td>
<input type="text" name="p1" value = "" size ="35" maxlength= "25">
</td>