Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <title></title>
- <meta charset="utf-8"/>
- <script src="jq.js" type="text/javascript"></script>
- <!--[if lt IE 7]>
- <script type="text/javascript">
- document.createElement("#date-star-month");
- document.createElement("#date-star-year");
- document.createElement("#date-finish-month");
- document.createElement("#date-finish-year");
- document.createElement("#date-star-month option");
- document.createElement("#date-star-year option");
- document.createElement("#date-finish-month option");
- document.createElement("#date-finish-year option");
- document.createElement("year_star");
- document.createElement("year_finish");
- </script>
- <![endif]-->
- </head>
- <body>
- <div class="desde">
- <select id="date-star-month">
- <option value="1">Enero</option>
- <option value="2">Febrero</option>
- <option value="3">Marzo</option>
- <option value="4">Abril</option>
- <option value="5">mayo</option>
- <option value="6">Junio</option>
- <option value="7">Julio</option>
- <option value="8">Agosto</option>
- <option value="9">Septiembre</option>
- <option value="10">Octubre</option>
- <option value="11">Noviembre</option>
- <option value="12">Diciembre</option>
- </select>
- <select id="date-star-year">
- <!-- <option selected="selected" value="2009">2009</option>
- <option value="2010">2010</option>
- <option value="2011">2011</option>
- <option value="2012">2012</option> -->
- </select>
- </div>
- <div class="hasta">
- <select id="date-finish-month">
- <option value="1">Enero</option>
- <option value="2">Febrero</option>
- <option value="3">Marzo</option>
- <option value="4">Abril</option>
- <option value="5">mayo</option>
- <option value="6">Junio</option>
- <option value="7">Julio</option>
- <option value="8">Agosto</option>
- <option value="9">Septiembre</option>
- <option value="10">Octubre</option>
- <option value="11">Noviembre</option>
- <option value="12">Diciembre</option>
- </select>
- <select id="date-finish-year">
- <!--<option selected="selected" value="2009">2009</option>
- <option value="2010">2010</option>
- <option value="2011">2011</option>
- <option value="2012">2012</option> -->
- </select>
- </div>
- <script>
- $(document).ready(function(){
- var month_star;
- var year_star;
- var year_finish;
- var year_igual = 0;
- var fecha_actual= new Date();
- var años= new Array();
- for(i=0; i<=(fecha_actual.getFullYear()-2008); i++){
- años[i]=2008+i;
- $("#date-finish-year").append("<option selected='selected' value='"+años[i]+"'>"+años[i]+"</option>");
- $("#date-star-year").append("<option selected='selected' value='"+años[i]+"'>"+años[i]+"</option>");
- }
- function month_convert(mes){
- switch(mes){
- case 1:
- return "Enero"
- case 2:
- return "febrero"
- case 3:
- return "marzo"
- case 4:
- return "abril"
- case 5:
- return "mayo"
- case 6:
- return "junio"
- case 7:
- return "julio"
- case 8:
- return "agosto"
- case 9:
- return "septiembre"
- case 10:
- return "octubre"
- case 11:
- return "noviembre"
- case 12:
- return "diciembre"
- }
- }
- mes_actual = fecha_actual.getMonth() + 1;
- //console.log(mes_actual);
- var mes_nombre = month_convert(mes_actual);
- //console.log(mes_nombre);
- $("#date-finish-month option").each(function(){
- if($(this).val() == mes_actual){
- console.log(mes_actual);
- $(this).attr("selected","selected");
- }
- });
- function each_finish_year(){
- year_star = parseInt($("#date-star-year").val());
- $("#date-finish-year option").each(function(){
- $(this).show();
- if ($(this).val()== year_star){
- $(this).attr("selected","selected");
- year_igual = 0;
- console.log(year_igual);
- }
- if ($(this).val() < year_star)
- $(this).hide();
- });
- }
- function select_hide(){
- $("#date-finish-month option").each(function(){
- $(this).show();
- if ($(this).val() < month_star)
- $(this).hide();
- });
- }
- function show_all(){
- $("#date-star-month option, #date-finish-month option").each(function(){
- $("#date-star-month option").show();
- $("#date-finish-month option").show();
- });
- }
- each_finish_year();
- $("#date-star-year").change(function(){
- year_star = parseInt($("#date-star-year").val());
- each_finish_year();
- });
- $("#date-finish-year").change(function(){
- year_star = parseInt($("#date-star-year").val());
- year_finish = parseInt($("#date-finish-year").val());
- if(year_star == year_finish){
- num_start_month=$("#date-star-month option:selected").val();
- num_finish_month=$("#date-finish-month option:selected").val();
- year_igual = 0;
- console.log(year_igual);
- month_star = parseInt($("#date-star-month").val());
- if(num_finish_month<num_start_month){
- $("#date-finish-month option:selected").attr("selected",false);
- $("#date-finish-month option[value="+num_start_month+"]").attr("selected",true);
- }
- select_hide();
- }
- else{
- year_igual = 1;
- console.log(year_igual);
- show_all();
- }
- });
- $("#date-star-year").change(function(){
- year_star = parseInt($("#date-star-year").val());
- year_finish = parseInt($("#date-finish-year").val());
- if(year_star == year_finish){
- num_start_month=$("#date-star-month option:selected").val();
- num_finish_month=$("#date-finish-month option:selected").val();
- year_igual = 0;
- console.log(year_igual);
- month_star = parseInt($("#date-star-month").val());
- if(num_finish_month<num_start_month){
- $("#date-finish-month option:selected").attr("selected",false);
- $("#date-finish-month option[value="+num_start_month+"]").attr("selected",true);
- }
- select_hide();
- }
- else{
- year_igual = 1;
- console.log(year_igual);
- show_all();
- }
- });
- $("#date-star-month").change(function(){
- year_star = parseInt($("#date-star-year").val());
- year_finish = parseInt($("#date-finish-year").val());
- month_star = parseInt($("#date-star-month").val());
- year_igual = 0;
- if(year_star == year_finish){
- num_start_month=$("#date-star-month option:selected").val();
- num_finish_month=$("#date-finish-month option:selected").val();
- year_igual = 0;
- console.log(year_igual);
- month_star = parseInt($("#date-star-month").val());
- if(num_finish_month<num_start_month){
- $("#date-finish-month option:selected").attr("selected",false);
- $("#date-finish-month option[value="+num_start_month+"]").attr("selected",true);
- }
- }
- if(year_igual == 0){
- select_hide();
- }
- if (year_igual == 1){
- show_all();
- }
- });
- });
- </Script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement