html
{foreach from=$month_arr item=dateArr key=i}
<tr>
<td>{$dateArr.m}</td>
<td>
<select name="start_Month" class='month start_month_{$i}'>
{foreach from=$dateArr.start_date.month item=monthList key=month_key}
{if $month_key==$dateArr.start_date.default_month}
<option value="{$month_key}" label="{$month_key}" selected="selected">{$monthList}</option>
{else}
<option value="{$month_key}" label="{$month_key}">{$monthList}</option>
{/if}
{/foreach}
</select>
<select name="start_Day" class="start_day_{$i}">
{foreach from=$dateArr.start_date.day item=dayList key=day_key}
{if $dayList == $dateArr.start_date.default_day}
<option value="{$dayList}" label="{$dayList}" selected="selected">{$dayList}</option>
{else}
<option value="{$dayList}" label="{$dayList}">{$dayList}</option>
{/if}
{/foreach}
</select>
{if $dateArr.start_date.year}
<select name="start_Year" class="start_year">
{foreach from=$dateArr.start_date.year item=yearList key=year_key}
<option value="{$yearList}" label="{$yearList}">{$yearList}</option>
{/foreach}
</select>
{/if}
<span class="start_date_{$i}"></span>
</td>
<td>
<select name="end_Month" class='month end_month_{$i}'>
{foreach from=$dateArr.end_date.month item=monthList key=month_key}
{if $month_key==$dateArr.end_date.default_month}
<option value="{$month_key}" label="{$month_key}" selected="selected">{$monthList}</option>
{else}
<option value="{$month_key}" label="{$month_key}">{$monthList}</option>
{/if}
{/foreach}
</select>
<select name="end_Day" class="end_day_{$i}">
{foreach from=$dateArr.end_date.day item=dayList key=day_key}
{if $dayList == $dateArr.end_date.default_day}
<option value="{$dayList}" label="{$dayList}" selected="selected">{$dayList}</option>
{else}
<option value="{$dayList}" label="{$dayList}">{$dayList}</option>
{/if}
{/foreach}
</select>
<span class="end_date_{$i}"></span>
</td>
</tr>
{/foreach}
<tr border='0'>
<td colspan="3">
<input type="submit" class="ibm-btn-arrow-pri" id="submit" name="submit" value="Submit">
</td>
</tr>
</tbody>
</table>
js
$(document).ready(function(){
var year = $("#year").val();
var month = '';
$('.month').change(function(){
var month = $(this).children('option:selected').val();
var this_month_str = $(this).attr('class');
var this_month_arr = this_month_str.split(' ');
var this_month = this_month_arr[1];
this_month = this_month.replace("month","day");
var month_type_arr = this_month.split('_');
var month_type = month_type_arr[0];
$('.'+month_type+'_month_'+month+ 'option[value='+this_month+']').attr("selected", true);
if(month){
$.post("url", {month: month, year:year},function(data){
var day_arr =(new Function("","return "+data))();
var max_num = day_arr.length;
var dateStr = '';
$.each(day_arr,function(index,value){
var str= "<option value="+day_arr[index]+">"+day_arr[index]+"</option>";
if(month_type=='end'){
if(day_arr[index]==max_num){
var str= "<option selected='selected' value="+day_arr[index]+">"+day_arr[index]+"</option>";
}
}
dateStr+=str;
});
$("."+this_month).html(dateStr);
});
}
});
$('.start_year').change(function(){
var start_year = $(this).children('option:selected').val();
$.post("url", {start_year: start_year, year:year},function(data){
var day_arr =(new Function("","return "+data))();
var monthStr = '';
var dayStr = '';
$.each(day_arr,function(index,value){
if(index=='month'){
$.each(value,function(m,val){
var mstr= "<option selected='selected' value="+m+">"+val+"</option>";
monthStr+= mstr;
});
}
if(index=='day'){
$.each(value,function(m,val){
var dstr= "<option selected='selected' value="+val+">"+val+"</option>";
dayStr+= dstr;
});
}
});
$(".start_month_1").html(monthStr);
$(".start_day_1").html(dayStr);
});
});
$('#submit').click(function(){
var year = $("#year").val();
var start_m_arr = new Array();
var start_m_all = "";
//$("select[name=start_Month] option[selected]").each(function (i) {
$("select[name=start_Month]").each(function (i) {
var val = $(this).val();
//var node = i!=11 ? val + "," : val ;
var node = val + ',';
start_m_arr.push(node);
start_m_all += node;
});
var start_d_arr = new Array();
var start_d_all = "";
//$("select[name=start_Day] option[selected]").each(function (i) {
$("select[name=start_Day]").each(function (i) {
var val = $(this).val();
//var node = i!=11 ? val + "," : val ;
var node = val + ',';
start_d_arr.push(node);
start_d_all += node;
});
var start_Year = '';
if($(".start_year")){
start_Year = $(".start_year").val();
}
var end_m_arr = new Array();
var end_m_all = "";
//$("select[name=end_Month] option[selected]").each(function (i) {
$("select[name=end_Month]").each(function (i) {
var val = $(this).val();
var node = i!=11 ? val + "," : val ;
end_m_arr.push(node);
end_m_all += node;
});
var end_d_arr = new Array();
var end_d_all = "";
//$("select[name=end_Day] option[selected]").each(function (i) {
$("select[name=end_Day]").each(function (i) {
var val = $(this).val();
var node = i!=11 ? val + "," : val ;
end_d_arr.push(node);
end_d_all += node;
});
if(start_m_all!='' && start_d_all!='' && end_m_all!='' && end_d_all!=''){
$.post("url", {start_Month: start_m_all, start_Day: start_d_all, end_Month: end_m_all,
end_Day: end_d_all, year:year, start_Year: start_Year},function(data){
var return_arr =(new Function("","return "+data))();
var status = return_arr.status;
if(status== true){
window.location.href = "url?year=" + year;
}else if(status== false){
alert('Added Period Billing error');
}
});
}
});
});