gpt4 book ai didi

javascript - 如何使用JS禁用表行并在MYSQL中插入所选选项?

转载 作者:行者123 更新时间:2023-11-29 11:31:43 27 4
gpt4 key购买 nike

我有一个动态显示表格行的 PHP 代码片段。每一行都有一个带有"is"和“否”选项的单选按钮。

我创建了一个JS函数,当用户选择一个选项时,会显示一个弹出框。

如果用户在单选按钮中选择"is"选项并在弹出框中单击“确定”,则表格行将被禁用,即使单选按钮也将被禁用。并且所选的选项将保存在MYSQL中。

如何在MySQL中保存选择的选项?

我的禁用行的 JS 片段不起作用。如何解决这个问题?

PHP:

echo '<td id="resumeFile"><a href="' . $dir  . $file . '">Download Resume</a></td>';
echo '<td id="radioOption">
<label for="Yes">Yes</label>
<input type="radio" id="processedOptionYes" name="processedOption" value="Yes" onclick="proccessedCheck()"/>
<label for="No">No</label>
<input type="radio" id="processedOptionNo" name="processedOption" value="No" onclick="proccessedCheck()"/></td>';

JS:

function proccessedCheck(){
var checked = null;
var inputs = document.getElementsByName('processedOption');
for (var i = 0; i < inputs.length; i++){
if (inputs[i].checked) {
checked = inputs[i];
break;
}
}

if(checked == null){
return false;
} else if (checked == true){
document.getElementById("resumeFile").disabled = true;
document.getElementById("radioOption").disabled = true;
document.getElementById("resumeFile").title = "This option has been disabled.";
} else {
return confirm('You have chosen '+ checked.value + ', is this correct?');
}
}

最佳答案

好吧,如果您要从 PHP 回显整个表格,只需将参数预设到表格中

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<script src="https://code.jquery.com/jquery-2.2.3.min.js" integrity="sha256-a23g1Nt4dtEYOj7bR+vTu7+T8VP13humZFBJNIYoEJo=" crossorigin="anonymous"></script>
<script>
function proccessedCheck(id,answer) {
if (confirm('You have chosen '+ id +': '+ answer + ', is this correct?')) {
$("#processedOptionYes"+id).attr('disabled',true);
$("#processedOptionNo"+id).attr('disabled',true);
var withlink = $("#resumeFile"+id).html();
var withoutlink = $(withlink).html();
$("#resumeFile"+id).html("").append(withoutlink);
$("#input1".val(id);
$("#input2".val(answer);
$("#myform").submit();

}
}
</script>

<!-- EDIT: hidden form to submit -->

<form id="myform" method="POST" action="savedb.php">
<input type="hidden" id="input1" name="id" />
<input type="hidden" id="input2" name="answer" />
</form>


<table>
<tr>
<?php
$dir="";
$file="";
$id = 0;
//foreach($array as $row) {
$id++;
echo '<td id="resumeFile'.$id.'"><a href="' . $dir . $file . '">Download Resume</a></td>';
echo '<td id="radioOption>
<label for="Yes">Yes</label>
<input type="radio" id="processedOptionYes'.$id.'" name="processedOption" value="Yes" onclick="proccessedCheck('.$id.',\'Yes\')"/>
<label for="No">No</label>
<input type="radio" id="processedOptionNo'.$id.'" name="processedOption" value="No" onclick="proccessedCheck('.$id.',\'No\')"/></td>';
//}
?>
</tr>
</table>
</body>
</html>

savedb.php 的内容,这不必是一个单独的文件

<?php

// Check if my post array arrived, comment this line when u done
echo "<pre>";print_r($_REQUEST);echo "</pre>"; die();

// Connect to DB
// Build SQL insert string with $_REQUEST['id'] as the primary key


?>

关于javascript - 如何使用JS禁用表行并在MYSQL中插入所选选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37289264/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com