admin管理员组文章数量:1384555
Hai i am developing application django where in i want to validate fromdate is less than todate.I am using the following code but it is not working
forms.py
class SearchFilterForm(Form):
fromdate = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'dd/mm/yy','class':'datefield','readonly':'readonly'}))
todate = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'dd/mm/yy','class':'datefield','readonly':'readonly'}))
javascript:
function paredate(){
var fromdate = document.getElementById("id_fromdate");
var todate = document.getElementById("id_todate");
if(fromdate<todate){
alert("Start date should be less than end date");
return false;
}
}
I am getting the input from date picker and the format is yy-mm-dd.The above code is not giving any error in console but it is not working.
Hai i am developing application django where in i want to validate fromdate is less than todate.I am using the following code but it is not working
forms.py
class SearchFilterForm(Form):
fromdate = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'dd/mm/yy','class':'datefield','readonly':'readonly'}))
todate = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'dd/mm/yy','class':'datefield','readonly':'readonly'}))
javascript:
function paredate(){
var fromdate = document.getElementById("id_fromdate");
var todate = document.getElementById("id_todate");
if(fromdate<todate){
alert("Start date should be less than end date");
return false;
}
}
I am getting the input from date picker and the format is yy-mm-dd.The above code is not giving any error in console but it is not working.
Share Improve this question asked Jun 20, 2013 at 14:45 Monk LMonk L 3,3689 gold badges28 silver badges42 bronze badges3 Answers
Reset to default 1document.getElementById("id_fromdate")
you are retrieving the node. What you need is the value
var fromdate = document.getElementById("id_fromdate").value;
var todate = document.getElementById("id_todate").value;
Then, you need to pare the dates, not just the string that .value
would retrieve.
var fromdate = document.getElementById("id_fromdate").value;
var todate = document.getElementById("id_todate").value;
You need to convert date value string date object then you can pare two date object
http://www.w3schools./jsref/jsref_obj_date.asp
Ex. var d1 = new Date();
var d2 = new Date();
if(+d1>+d2)
Try this
if (Date.parse(fromDate) > Date.parse(toDate)) {
alert("Invalid Date Range!\nStart Date cannot be after End Date!")
return false;
}
本文标签: javascriptcompare from date is less than to dateStack Overflow
版权声明:本文标题:javascript - compare from date is less than to date - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744521533a2610484.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论