我正在使用一个使用Javascript进行进程的表单。当我尝试使用 PHP 读取表单中的文本框值时,它没有显示输出。
我的代码是
HTMLCode 是
<form class="form-inline" method="POST" action="staff.php" onSubmit=" return questiontable()" >
<div class="form-group">
<label for="qscount">Number of Questions: </label>
<input type="number" name="qscount" class="form-control" id="qscount" style="width:150px;" placeholder="No of questions"> <br>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary" id="gobtn" onClick="return disable()" >Go</button> <br>
<p id="btnhide"> </p>
</div>
</form>
Javascript 是
<script type="text/javascript">
function questiontable()
{
var qs = document.getElementById("qscount").value;
var count;
for(count=1; count<=qs; count++)
{
document.getElementById("demo").innerHTML += '<br><font style="font-size: 20px">'+ count+'. <input class="textboxtest" style="width:850px;" type="text" name=" q'+ count +' " placeholder="Question "><br>' ;
document.getElementById("demo").innerHTML +='<br><input style="margin-left: 25px;" type="radio" name="a'+count+'" value="c1"> <input class="testbox" type="text" name="o'+count+'1" placeholder="Option 1">';
return false;
}
</script>
PHP 代码是
<?php
if (isset($_POST['qscount'])){
echo $_POST['qscount'];
}
?>
我想在另一个 php 页面中使用此 qscount 值。如何在PHP中获取此文本框值并在另一个页面中使用它?
Javascript function() 应该返回 true,因为你在按钮类型=submit 的 onclick 属性中使用了返回函数()
<script type="text/javascript">
function questiontable()
{
var qs = document.getElementById("qscount").value;
var count;
for(count=1; count<=qs; count++)
{
document.getElementById("demo").innerHTML += '<br><font style="font-size: 20px">'+ count+'. <input class="textboxtest" style="width:850px;" type="text" name=" q'+ count +' " placeholder="Question "><br>' ;
document.getElementById("demo").innerHTML +='<br><input style="margin-left: 25px;" type="radio" name="a'+count+'" value="c1"> <input class="testbox" type="text" name="o'+count+'1" placeholder="Option 1">';
}
return true;
}
</script>
这将继续在单击按钮时发布表单
如果您尝试使用 javascript 动态创建点击时的问题数量,
然后使用语法调用问题表
<button type="button" class="btn btn-primary" id="gobtn" onClick="javascript:return questiontable()" >Create Questions</button>
删除
onSubmit=" return questiontable()"
从表单
现在当问题表呈现时,请显示按钮类型="提交"
<button type=submit value="Go" name="cmdGo">Go</button>
触发表单提交
希望对您有所帮助!