javascript - 在将表单提交到数据库之前,我的代码没有执行我的 JS 函数
问题描述
processPhase8()
在将数据提交到数据库之前,我在执行 javascript 代码时遇到问题。数据被发送到数据库,但 JS 没有被执行,所以“决定”不会显示在数据库上。任何帮助将不胜感激。编程新手。
单击提交按钮后,我希望我的 JS 函数进行一些评分并将结果发送到<h1 class="alert-heading" id="decide" name="decide"></h1>
以便if (isset($_POST["submit"))
可以发送$decide = mysqli_real_escape_string($connection, $_POST["decide"])
到数据库:
// this is the javascript code I want to execute once the submit button is clicked before sending the form data to the database
function processPhase8()
{
if(creditscore >= possibleScore) {
_("decide").innerHTML="response1";
return true;
}
else if( creditscore === possibleScore) {
_("decide").innerHTML= "response2 "
;
return true;
}
else {
_("decide").innerHTML= "response3";
return true;
}
}
}
<?php
if(isset($_POST["submit"])) {
$decide = mysqli_real_escape_string($connection, $_POST["decide"]);
$query = "INSERT INTO users(decide) VALUES('$decide')";
mysqli_query($connection, $query ); // connect DB and process query
//create a variable to see if it went through
$result = mysqli_query($connection, $query ); // assign variable
if ($result) {
echo "<p style=font-size:30px;>Hurray, It Works!</p>"; } // checking that the query worked
} else {
echo " it didn't work";
}
?>
<head>
<script src="signupmulti.js"> </script>
</head>
<html>
<form method="post" action="signup.php" id="multiphase" onsubmit="return processPhase8()" enctype="multipart/form-data">
<div class="alert alert-success" role="alert">
<h1 class="alert-heading" id="decide" name="decide"></h1>
</div>
<button name="submit" type="submit" class="btn btn-lg btn-default">Click here for a decision </button>
</form>
</html>
解决方案
推荐阅读
- excel - 向 If Then 语句添加错误消息
- angularjs - angular-translate 防止 lang-keys 在路由更改后闪烁
- c++ - 只读来自 Kafka 主题的最后一条消息
- flyway - SQL 始终加密并转储迁移脚本以进行验证
- macos - 为什么更新钥匙串项目密码会导致重新提示应用程序访问?
- xodus - Jetbrains xodus 损坏的依赖项
- aws-vpc - aws账户如何区分?
- laravel - 生产中抛出异常,但开发中没有(pluck() on null)
- javascript - 为生产创建电子可执行文件时出错
- django - 如何使用自定义表单更新 django auth 用户