gpt4 book ai didi

javascript - HTML 单选按钮崩溃 JavaScript 表单功能

转载 作者:行者123 更新时间:2023-11-27 22:40:40 26 4
gpt4 key购买 nike

我正在开发一个表单 View ,该表单 View 提交到服务器以转换为文本文件。视线需要将数据post到服务器端php。它还需要在 URL 中添加“?PART_NO=part&frm=MF001”来命名每个文本文件。

如果表单包含多个单选按钮,则会导致 JavaScript 崩溃。这可能是因为我尝试访问表单元素的方式。我只需要访问名称为“Part_No”的文本字段。

<!DOCTYPE html>
<html>
<body>

<form id="test" method="post" action="http://10.0.0.252/test.php" onsubmit="process()">
<input type="checkbox" tabindex="40" id="form67_1" data-objref="458 0 R" name="box_brown" imageName="1/form/416 0 R" images="110100"/>
<input type="radio" tabindex="32" id="form68_1" data-objref="495 0 R" name="rc-50" value="yes" imageName="1/form/497 0 R" images="110100" checked="checked"/>
<input type="radio" tabindex="31" id="form69_1" data-objref="494 0 R" name="a2262at" value="no" imageName="1/form/494 0 R" images="110100"/>
<input type="radio" tabindex="17" id="form70_1" data-objref="509 0 R" name="process" value="no" imageName="1/form/509 0 R" images="110100"/>
<input type="radio" tabindex="11" id="form71_1" data-objref="503 0 R" name="master_glass" value="no" imageName="1/form/503 0 R" images="110100"/>
<input type="text" tabindex="4" id="form129_1" value="2" data-objref="62 0 R" title="Part No." name="Part_No"/>
<input type="submit" value="Submit">
</form>

<script>
function process() {
var form = document.getElementById('test');
var elements = form.elements["Part_No"];
var values = [];
values.push(encodeURIComponent(elements.name) + '=' + encodeURIComponent(elements.value) + "&frnm=MF001");

form.action += '?' + values;
}
</script>

</body>
</html>

如果有人感兴趣的话,这是服务器端脚本。

<?php
$name = $_GET['Part_No'];
$nom = $_GET['frnm'];
ob_start();
$file = $GLOBALS['HTTP_RAW_POST_DATA'];
$time = microtime(true);
$newfile = "./customers/" . $nom . "." . $name . "." . $time . ".txt";
$worked = file_put_contents($newfile, $file);
ob_end_clean();
exit();

?>

最佳答案

更改具有处理的单选按钮的名称或更改提交的函数名称,我建议更改函数名称如下

<!DOCTYPE html>
<html>
<body>

<form id="test" method="post" action="http://10.0.0.252/test.php" onsubmit="processForm()">
<input type="checkbox" tabindex="40" id="form67_1" data-objref="458 0 R" name="box_brown" imageName="1/form/416 0 R" images="110100"/>
<input type="radio" tabindex="32" id="form68_1" data-objref="495 0 R" name="rc-50" value="yes" imageName="1/form/497 0 R" images="110100" checked="checked"/>
<input type="radio" tabindex="31" id="form69_1" data-objref="494 0 R" name="a2262at" value="no" imageName="1/form/494 0 R" images="110100"/>
<input type="radio" tabindex="17" id="form70_1" data-objref="509 0 R" name="process" value="no" imageName="1/form/509 0 R" images="110100"/>
<input type="radio" tabindex="11" id="form71_1" data-objref="503 0 R" name="master_glass" value="no" imageName="1/form/503 0 R" images="110100"/>
<input type="text" tabindex="4" id="form129_1" value="2" data-objref="62 0 R" title="Part No." name="Part_No"/>
<input type="submit" value="Submit" />
</form>
<script type="text/javascript">
function processForm() {
alert("test");
var form = document.getElementById('test');
var elements = form.elements["Part_No"];
var values = [];
values.push(encodeURIComponent(elements.name) + '=' + encodeURIComponent(elements.value) + "&frnm=MF001");

form.action += '?' + values;
}
</script>


</body>
</html>

关于javascript - HTML 单选按钮崩溃 JavaScript 表单功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38769922/

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