[英]Bootstrap form not calling JS function on submit
I have the following code which consists of a form whose on submit calls a javascript function. 我有以下代码,该代码由一个表单组成,该表单的on Submit调用javascript函数。
<div class="form" role="form" onsubmit="createresult()">
<fieldset>
<?php
$subject = $_GET["sub"];
$array = mysqli_query($con, "Select * from questions where subject='$subject'");
$j =1;
while($row = mysqli_fetch_array($array))
{
echo "
<div class=\"form-group\"><h5>$row[question]</h5>";
for($i=1;$i<5;$i++)
{
$opt1 = "option".$i;
$opt = $row[$opt1];
$name = "question" ."$j";
echo "
<label class=\"radio-inline\">
<input type=\"radio\" name=$name required>$opt</label>";
}
echo "</div>";
$j++;
}
?>
<button type="submit" class="btn btn-primary" name="submit">Submit</button>
<button type="reset" class="btn btn-primary">Reset</button>
</fieldset>
</div>
The PHP script is working fine but this form is not calling the JavaScript function createresult()
. PHP脚本运行良好,但是此形式未调用JavaScript函数createresult()
。
https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onsubmit https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onsubmit
The submit event happens when a user clicks a submit button inside a <form>
tag. 当用户单击<form>
标记内的<form>
提交”按钮时,将发生Submit事件。 Right now you use a <div>
tag. 现在,您使用<div>
标签。
If you would like to use the <div>
tag, instead of using onsubmit
, use onclick
on the submit 如果要使用<div>
标记,而不是onsubmit
,请在提交时使用onclick
<button type="submit" class="btn btn-primary" name="submit" onclick="createresult()">Submit</button>
Change: 更改:
<div class="form" role="form" onsubmit="createresult()">
// your code
</div>
To 至
<form onsubmit="createresult()">
// your code
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.