【发布时间】:2015-03-07 13:29:40
【问题描述】:
在表单中使用 datepicker 获取日期并将日期值传递给 onchange 事件中的 javascript, 我试过这段代码,但不工作。
<form name="users" onchange="showUser(this.value)">
<label>Select By Date:</label>
<?php
include 'connection/db_connection.php';
echo '<div class="form-group">
<input type="text" name="date2" value="" class="form-control" id="dt2" required />
</div> ';
?>
</form>
我的脚本:
<script type="text/javascript">
function showUser(str) {
if (str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_export.php?q="+str,true);
xmlhttp.send();
}
</script>
我需要传递一个日期值并使用 where 子句从 mysql 表中获取记录
get_export.php:
<?php
$q = intval($_GET['q']);
include 'connection/db_connection.php';
$sql="SELECT * FROM admin_export where datetime='".$q."'";
$result = mysql_query($sql);
?>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<thead>
<?php
echo "
<th>SNO</th>
<th>Item Code</th>
<th>Product Name</th>
<th>Quantity</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody> ";
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo $row['sno']; // here not work
$sno=$row['sno'];
echo "<tr>";
echo "<td>" . $row['sno'] . "</td>";
echo "<td>" . $row['item_code'] . "</td>";
echo "<td>" . $row['product_name'] . "</td>";
echo "<td>" . $row['quantity'] . "</td>";
echo '<td><a href="edit_export.php?id='.$sno.'"> <img src="assets/img/icons/pencil.png" alt="Edit"></a></form></td>';
echo '<td> <form name="dform" action="delete_export.php?id='.$sno.'" method="POST" enctype="multipart/form-data">
<input type="submit" value="Delete" class="btn btn-primary"></input></form></td> ';
echo "</tr>";
}
echo "</tbody></table>";
mysql_close($con);
?>
【问题讨论】:
-
表单没有值?
-
一个论坛没有有值! - 没有问号。您在表单标签中使用 this.value,您希望发生什么?
-
this.value<form>? -
好的,如何将日期值传递给脚本?
-
只要从
id="dt2"得到它,反正很方便。在提交表单上禁用默认行为。并注意那个 SQL 注入漏洞。使用较新的 API 最好是 PDO 并使用准备好的语句
标签: javascript php mysql