在使用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表中获取recodsget_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);
?>
答案 0 :(得分:-1)
试试这个:
<form name="users" onchange="showUser(this)">
然后您可以通过以下方式访问:
function showUser(str)
{
var val = str.value;
}