I want to disable and enable the jQueryUI datepicker field when a radio button change. I use this code and first time works and destroy datepicker but when I change radio button, It doesn't build datepicker again.(when click first radio button, two upper datepicker should enable and two downer one should disable completely.when click second radio button,it should disable all the fields)
<tr>
<td>
<ct:selectOneRadio id="periodType"
onclick="submit();changeLableDate()"
label=""
labelKey="bond.bondPeriod"
value="#{bean.criteria.bondPeriod.periodTypeId}"
selectItems="#{bean.periodItems}"/>
</td>
<td colspan="3" style="width:65%"/>
</tr>
<tr>
<td style="width:35% !important;">
<ct:date id="fromDate2" value="#{bean.criteria.fromDate2}"
labelKey="reportCriteria.fromDate"
label="#{messages['reportCriteria.fromDate']}:"/>
</td>
<td/>
<td style="width:35% !important;">
<ct:date id="toDate2" value="#{bean.criteria.toDate2}"
labelKey="reportCriteria.toDate"
label="#{messages['reportCriteria.toDate']}:" />
</tr>
<tr>
<td style="width:35% !important;">
<ct:date id="fromDateIssue" value="#{bean.criteria.fromDateBond}"
labelKey="reportCriteria.fromDate"
label="#{messages['issue.fromDate']}:"
/>
</td>
<td/>
<td style="width:35% !important;">
<ct:date id="toDateIssue" value="#{bean.criteria.toDateBond}"
labelKey="reportCriteria.toDate"
label="#{messages['issue.toDate']}:" />
</td>
<td colspan="2" style="width:30%"/>
</tr>
<script type="text/javascript">
function changeLableDate() {
if (document.forms.reportForm["reportForm:periodType"][0].checked) {
$(".fromDateIssue").prop("disabled", true);
$(".toDateIssue").prop("disabled", true);
$(".toDate2").prop("disabled", false);
$(".fromDate2").prop("disabled", false);
$("#reportForm\\:fromDateIssue").datepicker("destroy");
$("#reportForm\\:toDateIssue").datepicker("destroy");
}
else if (document.forms.reportForm["reportForm:periodType"][1].checked) {
$("#reportForm\\:fromDate2").datepicker("destroy");
$("#reportForm\\:toDate2").datepicker("destroy");
$("#reportForm\\:fromDateIssue").datepicker("destroy");
$("#reportForm\\:toDateIssue").datepicker("destroy");
$(".fromDateIssue").prop("disabled", true);
$(".toDateIssue").prop("disabled", true);
$(".toDate2").prop("disabled", true);
$(".fromDate2").prop("disabled", true);
} }