onchange事件如何将日期值传递给javascript
在表单中,使用datepicker获取日期并在onchange事件中将日期值传递给javascript, 我试过这个代码,但不起作用onchange事件如何将日期值传递给javascript,javascript,php,mysql,Javascript,Php,Mysql,在表单中,使用datepicker获取日期并在onchange事件中将日期值传递给javascript, 我试过这个代码,但不起作用 <form name="users" onchange="showUser(this.value)"> <label>Select By Date:</label> <?php include 'connection/db_co
<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>
函数showUser(str){
如果(str==“”){
document.getElementById(“txtHint”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest){
//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}else{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”、“GET_export.php?q=“+str,true”);
xmlhttp.send();
}
我需要传递一个日期值,并使用where子句从mysql表中获取记录
获取_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);
?>
试试这个:
<form name="users" onchange="showUser(this)">
表单没有值?forom没有值没有问号。您在表单标记中使用了this.value,您希望发生什么?
在
上使用this.value
?好的,我如何将日期值传递给脚本?只需从id=“dt2”
获取它就可以了,这非常方便。在提交表单上禁用默认行为。并注意SQL注入漏洞。使用一个更新的API,最好是PDO,并使用prepared语句。关于这一点,我的错。我不知道您使用的是哪一个,但如果您使用引导日期选择器,您可以查看以下链接:
function showUser(str)
{
var val = str.value;
}