daniel-g of Nett
3/14/2017 - 10:20 PM

Lista de select o combo enlazada en javascript

Lista de select o combo enlazada en javascript

/*! Chained 1.0.0 - MIT license - Copyright 2010-2014 Mika Tuupola */
!function(a,b){"use strict";a.fn.chained=function(c){return this.each(function(){function d(){var d=!0,g=a("option:selected",e).val();a(e).html(f.html());var h="";a(c).each(function(){var c=a("option:selected",this).val();c&&(h.length>0&&(h+=b.Zepto?"\\\\":"\\"),h+=c)});var i;i=a.isArray(c)?a(c[0]).first():a(c).first();var j=a("option:selected",i).val();a("option",e).each(function(){a(this).hasClass(h)&&a(this).val()===g?(a(this).prop("selected",!0),d=!1):a(this).hasClass(h)||a(this).hasClass(j)||""===a(this).val()||a(this).remove()}),1===a("option",e).size()&&""===a(e).val()?a(e).prop("disabled",!0):a(e).prop("disabled",!1),d&&a(e).trigger("change")}var e=this,f=a(e).clone();a(c).each(function(){a(this).bind("change",function(){d()}),a("option:selected",this).length||a("option",this).first().attr("selected","selected"),d()})})},a.fn.chainedTo=a.fn.chained,a.fn.chained.defaults={}}(window.jQuery||window.Zepto,window,document);
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  
</head>
<body>
<select id="mark" name="mark">
  <option value="">CIUDAD</option>
  <option value="mty">MONTERREY</option>
  <option value="chi">CHIHUAHUA</option>
  <option value="sal">SALTILLO</option>
</select>
<select id="series" name="series">
  <option value="">--</option>
  <option value="series-3" class="mty">HOSPITAL ALTA ESPECIALIDAD</option>
  <option value="series-5" class="mty">HOSPITAL CONCHITA</option>
  <option value="series-6" class="mty">HOSPITAL SUR</option>
  <option value="a3" class="chi">HOSPITAL DEL PARQUE</option>
  <option value="a4" class="chi">CENTRO DE ONCOLOG√ćA</option>
  <option value="a5" class="sal">HOSPITAL SALTILLO</option>
</select>
<script charset="utf-8">
  $(function(){
      $("#series").chained("#mark");
  });
  </script>
  </body>
  </html>