Advertisement
Guest User

Untitled

a guest
Oct 28th, 2011
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.62 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta charset="utf-8"/>
  6. <script src="jq.js" type="text/javascript"></script>
  7. <!--[if lt IE 7]>
  8. <script type="text/javascript">
  9. document.createElement("#date-star-month");
  10. document.createElement("#date-star-year");
  11. document.createElement("#date-finish-month");
  12. document.createElement("#date-finish-year");
  13. document.createElement("#date-star-month option");
  14. document.createElement("#date-star-year option");
  15. document.createElement("#date-finish-month option");
  16. document.createElement("#date-finish-year option");
  17. document.createElement("year_star");
  18. document.createElement("year_finish");
  19. </script>
  20. <![endif]-->
  21. </head>
  22. <body>
  23.  
  24. <div class="desde">
  25. <select id="date-star-month">
  26. <option value="1">Enero</option>
  27. <option value="2">Febrero</option>
  28. <option value="3">Marzo</option>
  29. <option value="4">Abril</option>
  30. <option value="5">mayo</option>
  31. <option value="6">Junio</option>
  32. <option value="7">Julio</option>
  33. <option value="8">Agosto</option>
  34. <option value="9">Septiembre</option>
  35. <option value="10">Octubre</option>
  36. <option value="11">Noviembre</option>
  37. <option value="12">Diciembre</option>
  38. </select>
  39. <select id="date-star-year">
  40. <!-- <option selected="selected" value="2009">2009</option>
  41. <option value="2010">2010</option>
  42. <option value="2011">2011</option>
  43. <option value="2012">2012</option> -->
  44. </select>
  45. </div>
  46.  
  47. <div class="hasta">
  48. <select id="date-finish-month">
  49. <option value="1">Enero</option>
  50. <option value="2">Febrero</option>
  51. <option value="3">Marzo</option>
  52. <option value="4">Abril</option>
  53. <option value="5">mayo</option>
  54. <option value="6">Junio</option>
  55. <option value="7">Julio</option>
  56. <option value="8">Agosto</option>
  57. <option value="9">Septiembre</option>
  58. <option value="10">Octubre</option>
  59. <option value="11">Noviembre</option>
  60. <option value="12">Diciembre</option>
  61. </select>
  62. <select id="date-finish-year">
  63. <!--<option selected="selected" value="2009">2009</option>
  64. <option value="2010">2010</option>
  65. <option value="2011">2011</option>
  66. <option value="2012">2012</option> -->
  67. </select>
  68. </div>
  69. <script>
  70.  
  71. $(document).ready(function(){
  72. var month_star;
  73. var year_star;
  74. var year_finish;
  75. var year_igual = 0;
  76. var fecha_actual= new Date();
  77. var años= new Array();
  78. for(i=0; i<=(fecha_actual.getFullYear()-2008); i++){
  79. años[i]=2008+i;
  80. $("#date-finish-year").append("<option selected='selected' value='"+años[i]+"'>"+años[i]+"</option>");
  81. $("#date-star-year").append("<option selected='selected' value='"+años[i]+"'>"+años[i]+"</option>");
  82. }
  83.  
  84. function month_convert(mes){
  85. switch(mes){
  86. case 1:
  87. return "Enero"
  88. case 2:
  89. return "febrero"
  90. case 3:
  91. return "marzo"
  92. case 4:
  93. return "abril"
  94. case 5:
  95. return "mayo"
  96. case 6:
  97. return "junio"
  98. case 7:
  99. return "julio"
  100. case 8:
  101. return "agosto"
  102. case 9:
  103. return "septiembre"
  104. case 10:
  105. return "octubre"
  106. case 11:
  107. return "noviembre"
  108. case 12:
  109. return "diciembre"
  110. }
  111. }
  112.  
  113. mes_actual = fecha_actual.getMonth() + 1;
  114. //console.log(mes_actual);
  115.  
  116. var mes_nombre = month_convert(mes_actual);
  117. //console.log(mes_nombre);
  118.  
  119. $("#date-finish-month option").each(function(){
  120. if($(this).val() == mes_actual){
  121. console.log(mes_actual);
  122. $(this).attr("selected","selected");
  123. }
  124.  
  125. });
  126.  
  127. function each_finish_year(){
  128. year_star = parseInt($("#date-star-year").val());
  129. $("#date-finish-year option").each(function(){
  130. $(this).show();
  131. if ($(this).val()== year_star){
  132. $(this).attr("selected","selected");
  133. year_igual = 0;
  134. console.log(year_igual);
  135. }
  136. if ($(this).val() < year_star)
  137. $(this).hide();
  138. });
  139. }
  140.  
  141. function select_hide(){
  142. $("#date-finish-month option").each(function(){
  143. $(this).show();
  144. if ($(this).val() < month_star)
  145. $(this).hide();
  146.  
  147. });
  148. }
  149.  
  150. function show_all(){
  151. $("#date-star-month option, #date-finish-month option").each(function(){
  152. $("#date-star-month option").show();
  153. $("#date-finish-month option").show();
  154. });
  155. }
  156.  
  157. each_finish_year();
  158.  
  159. $("#date-star-year").change(function(){
  160. year_star = parseInt($("#date-star-year").val());
  161.  
  162. each_finish_year();
  163. });
  164.  
  165. $("#date-finish-year").change(function(){
  166. year_star = parseInt($("#date-star-year").val());
  167. year_finish = parseInt($("#date-finish-year").val());
  168.  
  169. if(year_star == year_finish){
  170. num_start_month=$("#date-star-month option:selected").val();
  171. num_finish_month=$("#date-finish-month option:selected").val();
  172. year_igual = 0;
  173. console.log(year_igual);
  174. month_star = parseInt($("#date-star-month").val());
  175. if(num_finish_month<num_start_month){
  176. $("#date-finish-month option:selected").attr("selected",false);
  177. $("#date-finish-month option[value="+num_start_month+"]").attr("selected",true);
  178. }
  179. select_hide();
  180.  
  181. }
  182.  
  183.  
  184. else{
  185. year_igual = 1;
  186. console.log(year_igual);
  187. show_all();
  188.  
  189. }
  190. });
  191.  
  192. $("#date-star-year").change(function(){
  193. year_star = parseInt($("#date-star-year").val());
  194. year_finish = parseInt($("#date-finish-year").val());
  195.  
  196. if(year_star == year_finish){
  197. num_start_month=$("#date-star-month option:selected").val();
  198. num_finish_month=$("#date-finish-month option:selected").val();
  199. year_igual = 0;
  200. console.log(year_igual);
  201. month_star = parseInt($("#date-star-month").val());
  202. if(num_finish_month<num_start_month){
  203. $("#date-finish-month option:selected").attr("selected",false);
  204. $("#date-finish-month option[value="+num_start_month+"]").attr("selected",true);
  205. }
  206. select_hide();
  207. }
  208.  
  209. else{
  210. year_igual = 1;
  211. console.log(year_igual);
  212. show_all();
  213.  
  214. }
  215. });
  216.  
  217. $("#date-star-month").change(function(){
  218. year_star = parseInt($("#date-star-year").val());
  219. year_finish = parseInt($("#date-finish-year").val());
  220. month_star = parseInt($("#date-star-month").val());
  221. year_igual = 0;
  222. if(year_star == year_finish){
  223. num_start_month=$("#date-star-month option:selected").val();
  224. num_finish_month=$("#date-finish-month option:selected").val();
  225. year_igual = 0;
  226. console.log(year_igual);
  227. month_star = parseInt($("#date-star-month").val());
  228. if(num_finish_month<num_start_month){
  229. $("#date-finish-month option:selected").attr("selected",false);
  230. $("#date-finish-month option[value="+num_start_month+"]").attr("selected",true);
  231. }
  232.  
  233. }
  234.  
  235. if(year_igual == 0){
  236. select_hide();
  237. }
  238. if (year_igual == 1){
  239. show_all();
  240. }
  241. });
  242.  
  243. });
  244. </Script>
  245.  
  246. </body>
  247. </html>
  248.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement