# Compare dates client side

greendragon
25 4

Hello! I've a form with two dates, and I wanto to insert a constrait on them: the second date must be grater than the first date. I want to do this client side but I've no idea how get the values inserted in dateboxes. This is my code:

...
<datebox id="fromDate" format="short" constraint="no past" value="@bind(myVM.fromDate)"></datebox>
<datebox format="short" constraint="no past" value="@bind(myVM.toDate)"
w:onChange="changeDate();"></datebox>
...
<script type="text/javascript">
function changeDate() {
var x = jq('$toDate'); ...???... } </script>  How can I get the date value from x? Very thanks... delete retag edit ## 5 Answers Sort by » oldest newest most voted answered 2015-10-08 15:04:48 +0800 jumperchen 3909 2 8 http://jumperchen.blogspo... either way is the same. jq('$db').zk.$().getValue() // or zk('$db').$().getValue();  answered 2015-10-08 15:12:06 +0800 Darksu 1991 1 4 Hello greendragon, Please use the following code in order to update the second datebox with the value from the first one: <zk xmlns:w="client"> <datebox id="dbx" w:onChange=" var origin = zk.Widget.$('$dbx'); var t = zk.Widget.$('$dbx2'); t.$n('real').value=( origin.$n('real').value ); t.updateChange_();" /> <datebox id="dbx2" /> </zk>  Best Regards, Darksu answered 2015-10-09 12:53:06 +0800 greendragon 25 4 Thanks! Both the answers are working! answered 2015-10-14 10:53:43 +0800 greendragon 25 4 Hello! I solved the problem with the datebox: var toDate = new Date(jq('$toDate').zk.$().getValue());  Thanks answered 2015-10-14 11:03:52 +0800 Darksu 1991 1 4 Hello greendragon, Here is the respective with timebox: <zk xmlns:w="client"> <timebox id="dbx" w:onClick=" var origin = zk.Widget.$('$dbx'); var t = zk.Widget.$('$dbx2'); t.$n('real').value=( origin.\$n('real').value );
t.updateChange_();" />
<timebox id="dbx2"  />
</zk>


You had to change the component, and use the onClick event in order to make it work.

Best Regards,

Darksu

[hide preview]