"","pass" => "","database" => ""]; $db = nu-6ren">
gpt4 book ai didi

javascript - 如何使用 `id` 而不是 `name` 发布 HTML 表单

转载 作者:行者123 更新时间:2023-11-30 09:56:37 25 4
gpt4 key购买 nike

下面这段代码将通过名称获取元素,我将其更改为通过 ID 获取元素,如何实现?

<?
if($_SERVER["REQUEST_METHOD"] == "POST" && array_key_exists("calculateFormSubmit", $_POST)) {
$connectionData = ["server" => "","user" => "","pass" => "","database" => ""];
$db = null;
try {
$db = new PDO("mysql:host=" . $connectionData["server"] . ";dbname=" . $connectionData["database"], $connectionData["user"], $connectionData["pass"]);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
echo $e->getMessage();
}

$dateFrom = (int)$_POST["YearBox"] . "-" . (int)$_POST["gmonth"] . "-" . (int)$_POST["gday1"];
$dateTo = (int)$_POST["gyear2"] . "-" . (int)$_POST["gmonth2"] . "-" . (int)$_POST["gday2"];
$stmt = $db->prepare("SELECT SUM(rialamount) as sum_result FROM problem_tbl WHERE opening_date BETWEEN STR_TO_DATE(:date_from, '%Y-%c-%e') AND STR_TO_DATE(:date_to, '%Y-%c-%e')");

$stmt->bindValue(":date_from", $dateFrom);
$stmt->bindValue(":date_to", $dateTo);
$stmt->execute();
$userData = $stmt->fetchAll(PDO::FETCH_ASSOC);

if($userData != false) {
foreach ($userData as $idPatient) {
header('Content-Type: text/html; charset=utf-8');
echo "<p>Text Here </p>\n";
echo "<div id=\"rialamount\" style=\"text-shadow: 2px 2px 5px #0B4D09; font-size: 140%;\">\n";
echo "<b>" . [''] . "<b> - " . $idPatient["sum_result"] . "<br />";
echo "</div>\n";
}
}

if($db !== null) {
$db = null;
}
}
?>

$dateFrom$dateTo 中会按类名获取元素,如何更改为按ID 获取元素??

提前致谢

最佳答案

你不能通过 ID 在 php 中检索数据它适用于名称..所以你需要更改

PHP

<form method="POST" action="nextpage.php" name="myform" id="myform">
<input type="text" id="rout_markers" name="rout_markers"/>
<input type="hidden" name="someNewName" id="someNewName" value="" />
<input type="submit" id="send-btn" class="button" value="SEND NOW" onclick="submitform()" />
</form>

jQuery

$("form").bind('submit',function(e){
e.preventDefault();
var hiddenData=$("input[name=rout_markers]").val();
// or var hiddenData=jQuery('#rout_markers').val();
$("input[type=hidden][name=someNewName]").val(hiddenData);
});

nextpage.php

通过以下方式获取数据

$_POST['someNewName'];

更新

在提交按钮中设置onclick=submitform() 并为表单分配nameid 属性并编写此

javascript

<script type="text/javascript">
function submitform()
{
var hiddenData = document.getElementById('rout_markers').value;
document.getElementById('someNewName').value = hiddenData;
document.myform.submit();
}
</script>

有关详细信息,请单击 getting values from ID instead of name

关于javascript - 如何使用 `id` 而不是 `name` 发布 HTML 表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33636143/

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