jquery Gets the value of multiple select name

Source: Internet
Author: User

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 ');
}
});
}
});
});

jquery Gets the value of multiple select name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.