Coder
Coder

Reputation: 79

How can you trigger the jquery datepicker function in Struts?

I would like to trigger an event in jquery datepicker ,but when i select a particular date ,its not been triggered.

This is my code for validation of the from date and to date, what should I do to make this function active?

$("#fromDate").datepicker({            
    numberOfMonths: 1,
    onselect: function (selected) {
        alert("hello");
        var dt = new Date(selected);
        dt.setDate(dt.getDate() + 1);
        $("#toDate").datepicker("option", "minDate", dt);
    }
});

$("#toDate").datepicker({
    numberOfMonths: 1,
    onselect: function (selected) {
        var dt = new Date(selected);
        dt.setDate(dt.getDate() - 1);
        $("#fromDate").datepicker("option", "maxDate", dt);         
    }
});

Upvotes: 3

Views: 322

Answers (2)

Pranav C Balan
Pranav C Balan

Reputation: 115212

It's working as you expected, with jQuery-ui datepicker

var $from = $("#fromDate"),
  $to = $("#toDate");
$from.datepicker({
  numberOfMonths: 1,
  onSelect: function(selected) {
    alert("hello");
    var dt = new Date(selected);
    dt.setDate(dt.getDate() + 1);
    $to.datepicker("option", "minDate", dt);
  }
});

$to.datepicker({
  numberOfMonths: 1,
  onSelect: function(selected) {
    var dt = new Date(selected);
    dt.setDate(dt.getDate() - 1);
    $from.datepicker("option", "maxDate", dt);
  }
});
<link href="http://code.jquery.com/ui/1.11.3/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.3/jquery-ui.min.js"></script>
<input type="text" id="fromDate" />
<input type="text" id="toDate" />

Upvotes: 1

Gandar
Gandar

Reputation: 61

You have to write the function properly. It's onSelect, with an uppercase 'S'

Upvotes: 1

Related Questions