admin管理员组文章数量:1323716
This is a function I need to call when my JQuery date picker selects both to and from dates:
function showUser() {
// Retrieve values from the selects
var DateFrom = document.getElementById('DateFrom').value;
var DateTo = document.getElementById('DateTo').value;
if (dtd=="" || dtm == "" || dfd == "" || dfm == "") {
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","/StreetHailDrivers.php?DateFrom="+DateFrom+"&DateTo="+DateTo,true);
xmlhttp.send();
}
and this is my datepicker:
$(function() {
$('.datepicker').datepicker({ onSelect: showUser(), minDate: -90, maxDate: "+1D" });
});
If i take out the onSelect: showUser()
The datepicker works fine, but doesnt post the data, but if i include the onselect the datepicker doesnt work. no drop down.
I also tried the onchange event in the html:
<input type="text" class="datepicker" name="DateTo" id="DateTo" onchange="showUser()" />
what should I do to get it working?
This is a function I need to call when my JQuery date picker selects both to and from dates:
function showUser() {
// Retrieve values from the selects
var DateFrom = document.getElementById('DateFrom').value;
var DateTo = document.getElementById('DateTo').value;
if (dtd=="" || dtm == "" || dfd == "" || dfm == "") {
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","/StreetHailDrivers.php?DateFrom="+DateFrom+"&DateTo="+DateTo,true);
xmlhttp.send();
}
and this is my datepicker:
$(function() {
$('.datepicker').datepicker({ onSelect: showUser(), minDate: -90, maxDate: "+1D" });
});
If i take out the onSelect: showUser()
The datepicker works fine, but doesnt post the data, but if i include the onselect the datepicker doesnt work. no drop down.
I also tried the onchange event in the html:
<input type="text" class="datepicker" name="DateTo" id="DateTo" onchange="showUser()" />
what should I do to get it working?
Share Improve this question asked Jan 14, 2014 at 23:15 MikeMike 5213 gold badges10 silver badges31 bronze badges1 Answer
Reset to default 4jsFiddle Demo
The main issue is that the function showUser is not defined in a scope available to the scope where the datepicker is assigned. The result is more than likely an error that you can see in your console: "Uncaught ReferenceError: showUser is not defined ". When the error is caused all of the script execution is halted and the datepicker is not constructed. You should make sure that the datepicker object has access to this function.
I believe it is expecting a pointer to a function for that parameter. As such it should probably be
onSelect: showUser
Using onSelect: showUser()
will set the value of onSelect
to the return value of showUser
which is undefined.
本文标签: javascriptJquery Datepicker onselect call functionStack Overflow
版权声明:本文标题:javascript - Jquery Datepicker onselect call function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742125284a2421911.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论