<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#start_year, #start_month, #end_year, #end_month").change(function() { var checkNum = 2;//3개월이면 2로 셋팅 //선택된 값을 가져온다. var startYear = $("#start_year option:selected").val(); var startMonth = $("#start_month option:selected").val(); var endYear = $("#end_year option:selected").val(); var endMonth = $("#end_month option:selected").val(); //계산을 위해 명시적으로 형변환 var startYearNum = Number(startYear); var startMonthNum = Number(startMonth); var endYearNum = Number(endYear); var endMonthNum = Number(endMonth); //일단 차이를 재서 위에서 정한 월이 넘어가는지 확인 var result = ((endYearNum*12)+endMonthNum) - ((startYearNum*12)+startMonthNum); if(result>checkNum){ alert("날짜 검색 범위는 "+(checkNum+1)+"개월 입니다."); if(endMonthNum<=checkNum){ startYearNum = endYearNum-1; startMonthNum = 12-(checkNum-endMonthNum) }else{ startYearNum = endYearNum; startMonthNum = endMonthNum-checkNum; } $("#start_year").val(startYearNum).attr("selected", "selected"); $("#start_month").val(startMonthNum).attr("selected", "selected"); }; }); }); </script> <select id="start_year" name="start_year"> <option value="2015" >2015</option> <option value="2014" >2014</option> <option value="2013" >2013</option> </select> <select id="start_month" name="start_month"> <option value="1" >1</option> <option value="2" >2</option> <option value="3" >3</option> <option value="4" >4</option> <option value="5" >5</option> <option value="6" >6</option> <option value="7" >7</option> <option value="8" >8</option> <option value="9" >9</option> <option value="10" >10</option> <option value="11" >11</option> <option value="12" >12</option> </select> ~ <select id="end_year" name="end_year"> <option value="2015" >2015</option> <option value="2014" >2014</option> <option value="2013" >2013</option> </select> <select id="end_month" name="end_month"> <option value="1" >1</option> <option value="2" >2</option> <option value="3" >3</option> <option value="4" >4</option> <option value="5" >5</option> <option value="6" >6</option> <option value="7" >7</option> <option value="8" >8</option> <option value="9" >9</option> <option value="10" >10</option> <option value="11" >11</option> <option value="12" >12</option> </select> <input type="image" src="/images/button/search.gif" alt="검색" class="img"/>
제목을 뭘로 정해야 할지 몰라서 그냥 막 적었습니다.
아래 소스를 확인하시면 년도에 12개월을 곱해서 계산 했습니다. ㅋㅋ