Foros del Web » Programando para Internet » Jquery »

[SOLUCIONADO] provocar un evento

Estas en el tema de provocar un evento en el foro de Jquery en Foros del Web. Buenas, Tengo un checkbox que a través de jquery controlo cuando lo activan o desactivan. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Javascript : Ver original $ ( "#seleccion" ...
  #1 (permalink)  
Antiguo 12/10/2015, 06:41
 
Fecha de Ingreso: enero-2002
Ubicación: Sabadell
Mensajes: 565
Antigüedad: 22 años, 3 meses
Puntos: 4
provocar un evento

Buenas,
Tengo un checkbox que a través de jquery controlo cuando lo activan o desactivan.

Código Javascript:
Ver original
  1. $("#seleccion").on('change', function(){
  2. ...
  3. });

Necesito según valor de parámetro de acceso a la web, ponerlo a true, por ello hago lo siguiente:

Código Javascript:
Ver original
  1. $(document).ready(function(){
  2. if (tipo == 3)
  3.     alert ("ok");
  4.     $("#seleccion").prop('checked', true);
  5.     $("#seleccion").trigger('change');
  6. }

Y el evento:

Código Javascript:
Ver original
  1. $("#seleccion").on('change', function(){
  2.         ...
  3. });

El mensaje de ok aparece, pero no provoca el evento.

Qué estoy haciendo mal? Gracias
__________________
Qué fácil cuando lo sabes y qué difícil cuando no

Última edición por mblascog; 12/10/2015 a las 10:22
  #2 (permalink)  
Antiguo 12/10/2015, 11:36
 
Fecha de Ingreso: enero-2014
Ubicación: Navarra
Mensajes: 94
Antigüedad: 10 años, 4 meses
Puntos: 18
Respuesta: provocar un evento

Hola.

Despues de if (tipo == 3) te falta la llave de apertura {

de todas formas el codigo que has puesto a mi me funciona bien,
habria que ver todo el codigo para ver si hay algun conflicto de eventos.

saludos.
  #3 (permalink)  
Antiguo 12/10/2015, 13:09
 
Fecha de Ingreso: enero-2002
Ubicación: Sabadell
Mensajes: 565
Antigüedad: 22 años, 3 meses
Puntos: 4
Respuesta: provocar un evento

Buenas, sí falta la llave, ha sido error del copiar.
No tengo problemas en poner el código, pero es muy largo. Lleva mucho tiempo funcionando, lo que ahora necesito es lanzar manualmente el evento
Código Javascript:
Ver original
  1. $("#seleccion").on('change', function(){
  2. });
pero no lo consigo.

Yo pensaba que al poner el checkbox, al inicio, a true, automáticamente se lanzaría el evento, pero no es así. Por internet he leído de lanzar el evento con trigger, pero tampoco.

También he pensado en la posibilidad de algún conflicto, pero no he encontrado nada

Gracias.
__________________
Qué fácil cuando lo sabes y qué difícil cuando no
  #4 (permalink)  
Antiguo 12/10/2015, 14:35
Avatar de Trublux  
Fecha de Ingreso: octubre-2010
Ubicación: Madrid
Mensajes: 355
Antigüedad: 13 años, 6 meses
Puntos: 48
Respuesta: provocar un evento

Tienes errores en el código que pones.
A parte de lo que te dice @sintel_1 el "document.ready" no lo cierras (no sé si lo has copiado mal o es que lo tiene mal).

OJO: Tienes que cargar el trigger después de la función que captura el evento change.

Mira lo que te dice la consola porque he hecho la prueba y funciona sin problemas.

Esto es lo que yo he puesto y me funciona:
Código Javascript:
Ver original
  1. $(function () {
  2.     $('#seleccion').on('change', function () {
  3.         console.log('Cambiado');
  4.     });
  5.  
  6.     if ( tipo == 3 ) {
  7.         $("#seleccion").trigger('change');
  8.     }
  9. });
__________________
eZ Publish Developer Basic Legacy
eZ Publish Developer Basics (4.4)
Alojamientos rurales en España
  #5 (permalink)  
Antiguo 12/10/2015, 14:57
 
Fecha de Ingreso: enero-2002
Ubicación: Sabadell
Mensajes: 565
Antigüedad: 22 años, 3 meses
Puntos: 4
Respuesta: provocar un evento

Buenas y gracias por vuestra colaboración.
El código funciona y no contiene errores. Lo que veis han sido en el momento de transcribirlo.

A continuación copiaré el código. Siguiendo paso a paso la ejecución, afirmo que pasa por dentro del case "3", cambia el estado a true del div selPisosCases, pero no lanza el evento de cambio.

No lo entiendo, quizás hay algún conflicto pero no lo detecto.

Código Javascript:
Ver original
  1. <script>
  2.     $(document).ready(function(){
  3.         $(function () {
  4.  
  5.         tipus = "<?php echo $_tipus ?>";
  6.         switch(tipus) {
  7.             case "3":
  8.                 $("#selPisosCases").prop('checked', true);
  9.                 $("#selPisosCases").trigger('change');
  10.                 break;
  11.             case "5":
  12.                 break;
  13.             case "6":
  14.                 break;
  15.             case "7":
  16.                 break;
  17.             case "8":
  18.                 break;
  19.             case "0":
  20.                 break;
  21.         }
  22.  
  23.         $("#desglosPisosCases").hide();
  24.         $("#desglosLocalsOficines").hide();
  25.         $("#desglosNausIndustrials").hide();
  26.         $("#desglosSolarsParceles").hide();
  27.         $("#desglosParquings").hide();
  28.         $("#desglosBarris").hide();
  29.         var op = 0; //operacio: 0=tots; 1=compra; 2=lloguer
  30.         var ob = 0; //oportunitat bancària: 0:tots; 1=no ob; 2=només ob
  31.         var prmTipus = ""; var prmCiutat = ""; var prmPreu = ""; var prmHabitacions = ""; var prmMetres = ""; var prmCiutat = ""; var prmOrdre = ""; var prmDireccio = ""; var prmBarris = "";
  32.         var pisosCases = ["908119896.50019", "897431778.50019", "935651163.50019", "3", "949016947.50019", "900892021.50019", "4", "299136542.50019", "935170816.50019"];
  33.         var localsOficines = ["7", "218592849.50019", "877918607.50019", "329189847.50019"];
  34.         var solarsParceles = ["5", "880782203.50019", "884930416.50019", "932673848.50019", "463133863.50019", "954401543.50019"];
  35.         var habitacions = ["= 1", "= 2", "= 3", "= 4", "> 4"];
  36.         var destacats = "";
  37.         $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"1"}, function(data){$("#recTotal").html(data);})                           
  38.         $.post("<?php echo URL.'includes/inc_getOrdre.php'?>", {prm:"Preu"+"-"+"<?php echo $idioma?>"}, function(data){$("#selectOrdrePreu").html(data);});
  39.         $.post("<?php echo URL.'includes/inc_getOrdre.php'?>", {prm:"M2"+"-"+"<?php echo $idioma?>"}, function(data){$("#selectOrdreM2").html(data);});
  40.         $.post("<?php echo URL.'includes/inc_getOrdre.php'?>", {prm:"Habitacions"+"-"+"<?php echo $idioma?>"}, function(data){$("#selectOrdreHabitacions").html(data);});  
  41.         $.post("<?php echo URL.'includes/inc_getOrdre.php'?>", {prm:"Ciutat"+"-"+"<?php echo $idioma?>"}, function(data){$("#selectOrdreCiutat").html(data);});
  42.         $.post("<?php echo URL.'includes/inc_getBarris.php'?>", function(data){$("#desglosBarris").html(data);});  
  43.         $.post("<?php echo URL.'includes/inc_perPoblacions.php'?>", function(data){$("#poblacions").html(data);}); 
  44.         $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"2"+"-"+"4"}, function(data){$("#totalCompra").html("("+data+")");});
  45.         $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"2"+"-"+"3"}, function(data){$("#totalLloguer").html("("+data+")");});
  46.         $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"6"+"-"+"1"}, function(data){$("#senseOP").html("("+data+")");});
  47.         $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"6"+"-"+"2"}, function(data){$("#ambOP").html("("+data+")");});
  48.    
  49.         refresca(op, ob);
  50.        
  51.         $("#selCompra").on('click', function(){
  52.             if (this.checked) {
  53.                 $("#selLloguer").prop('checked', false);
  54.                 op = 1;
  55.             }
  56.             else
  57.                 op = 0;
  58.             refresca(op, ob)
  59.         });                
  60.  
  61.         $("#selLloguer").on('change', function(){
  62.             if (this.checked) {
  63.                 $("#selCompra").prop('checked', false);
  64.                 op = 2;
  65.             }
  66.             else
  67.                 op = 0;
  68.             refresca(op, ob)
  69.         });
__________________
Qué fácil cuando lo sabes y qué difícil cuando no
  #6 (permalink)  
Antiguo 12/10/2015, 14:58
 
Fecha de Ingreso: enero-2002
Ubicación: Sabadell
Mensajes: 565
Antigüedad: 22 años, 3 meses
Puntos: 4
Respuesta: provocar un evento

Código Javascript:
Ver original
  1. $("#selPisosCases").on('change', function(){
  2.             alert ("entro");
  3.             if (this.checked) {
  4.                 $("#selLocalsOficines").prop('checked', false);
  5.                 $("#selNausIndustrials").prop('checked', false);
  6.                 $("#selSolarsParceles").prop('checked', false);
  7.                 $("#selParquings").prop('checked', false);
  8.                 $("#selOportunitatsBancaries").prop('checked', false);
  9.                 $("#desglosPisosCases").show();
  10.                 $("#desglosLocalsOficines").hide();
  11.                 $("#desglosNausIndustrials").hide();
  12.                 $("#desglosSolarsParceles").hide();
  13.                 $("#desglosParquings").hide();
  14.                 $("#titolOrdreHabitacions").show();
  15.                 $("#selectOrdreHabitacions").show();
  16.                 visDestacats(3);
  17.                 tornaTipusPC();
  18.                 $.post("<?php echo URL.'includes/inc_getPoblacions.php'?>", {prm:prmTipus}, function(data){$("#selectCiutatPC").html(data);}); 
  19.                 refrescaDetall(0);
  20.             }
  21.             else
  22.                 $("#desglosPisosCases").hide();
  23.             netejaDetall();
  24.         });
  25.  
  26.         $(".subIndexPC").on('change', function() {
  27.             tornaTipusPC();
  28.             $.post("<?php echo URL.'includes/inc_getPoblacions.php'?>", {prm:prmTipus}, function(data){$("#selectCiutatPC").html(data);}); 
  29.             refrescaDetall(0);
  30.         });
  31.  
  32.  
  33.         $(".selectOrdre").change(function() {
  34.             prmOrdre = $(this).prop("id");
  35.             prmDireccio = $(this).val();
  36.             prmDireccio = prmDireccio.substr(-1);
  37.             netejaSelectOrdre("#" + prmOrdre);
  38.             $(this).css("width", "130px");
  39.             prmOrdre = prmOrdre.replace("selectOrdre", "");
  40.             $.post("<?php echo URL.'includes/inc_getImmobles.php'?>", {prm:op+"-"+ob+"-"+prmTipus+"-"+prmCiutat+"-"+prmPreu+"-"+prmHabitacions+"-"+prmMetres+"-"+prmOrdre+"-"+prmDireccio+"-"+prmBarris}, function(data){  
  41.                 visualitza(data);
  42.             })                         
  43.         });
  44.        
  45.         $("#selLocalsOficines").on('change', function(){
  46.  
  47.             if (this.checked) {
  48.                 $("#selPisosCases").prop('checked', false);
  49.                 $("#selNausIndustrials").prop('checked', false);
  50.                 $("#selSolarsParceles").prop('checked', false);
  51.                 $("#selParquings").prop('checked', false);
  52.                 $("#selOportunitatsBancaries").prop('checked', false);
  53.                 $("#desglosPisosCases").hide();
  54.                 $("#desglosLocalsOficines").show();
  55.                 $("#desglosNausIndustrials").hide();
  56.                 $("#desglosSolarsParceles").hide();
  57.                 $("#desglosParquings").hide();
  58.                 $("#titolOrdreHabitacions").hide();
  59.                 $("#selectOrdreHabitacions").hide();
  60.                 visDestacats(7);
  61.                 tornaTipusLO();
  62.                 $.post("<?php echo URL.'includes/inc_getPoblacions.php'?>", {prm:prmTipus}, function(data){$("#selectCiutatLO").html(data);}); 
  63.                 refrescaDetall(1);
  64.             }
  65.             else
  66.                 $("#desglosLocalsOficines").hide();
  67.             netejaDetall();
  68.         });
  69.  
  70.         $(".subIndexLO").on('change', function() {
  71.             tornaTipusLO();
  72.             $.post("<?php echo URL.'includes/inc_getPoblacions.php'?>", {prm:prmTipus}, function(data){$("#selectCiutatLO").html(data);}); 
  73.             refrescaDetall(1);
  74.         });
  75.        
  76.         $("#selNausIndustrials").on('change', function(){
  77.             if (this.checked) {
  78.                 $("#selPisosCases").prop('checked', false);
  79.                 $("#selLocalsOficines").prop('checked', false);
  80.                 $("#selSolarsParceles").prop('checked', false);
  81.                 $("#selParquings").prop('checked', false);
  82.                 $("#selOportunitatsBancaries").prop('checked', false);
  83.                 $("#desglosPisosCases").hide();
  84.                 $("#desglosLocalsOficines").hide();
  85.                 $("#desglosNausIndustrials").show();
  86.                 $("#desglosSolarsParceles").hide();
  87.                 $("#desglosParquings").hide();
  88.                 $("#titolOrdreHabitacions").hide();
  89.                 $("#selectOrdreHabitacions").hide();
  90.                 visDestacats(6);
  91.                 $.post("<?php echo URL.'includes/inc_getPoblacions.php'?>", {prm:"6"}, function(data){$("#selectCiutatNI").html(data);});  
  92.             }
  93.             else
  94.                 $("#desglosNausIndustrials").hide();
  95.             netejaDetall();
  96.         });
  97.        
  98.  
  99.         $("#selSolarsParceles").on('change', function(){
  100.             if (this.checked) {
  101.                 $("#selPisosCases").prop('checked', false);
  102.                 $("#selLocalsOficines").prop('checked', false);
  103.                 $("#selNausIndustrials").prop('checked', false);
  104.                 $("#selParquings").prop('checked', false);
  105.                 $("#selOportunitatsBancaries").prop('checked', false);
  106.                 $("#desglosPisosCases").hide();
  107.                 $("#desglosLocalsOficines").hide();
  108.                 $("#desglosNausIndustrials").hide();
  109.                 $("#desglosSolarsParceles").show();
  110.                 $("#desglosParquings").hide();
  111.                 $("#titolOrdreHabitacions").hide();
  112.                 $("#selectOrdreHabitacions").hide();
  113.                 visDestacats(8);
  114.                 tornaTipusSP();
  115.                 $.post("<?php echo URL.'includes/inc_getPoblacions.php'?>", {prm:prmTipus}, function(data){$("#selectCiutatSP").html(data);}); 
  116.                 refrescaDetall(3);
  117.             }
  118.             else
  119.                 $("#desglosSolarsParceles").hide();
  120.             netejaDetall();
  121.         });
  122.  
  123.         $(".subIndexSP").on('change', function() {
  124.             tornaTipusSP();
  125.             $.post("<?php echo URL.'includes/inc_getPoblacions.php'?>", {prm:prmTipus}, function(data){$("#selectCiutatSP").html(data);}); 
  126.             refrescaDetall(2);
  127.         });
  128.        
  129.        
  130.         $("#selParquings").on('change', function(){
  131.             if (this.checked) {
  132.                 $("#selPisosCases").prop('checked', false);
  133.                 $("#selLocalsOficines").prop('checked', false);
  134.                 $("#selNausIndustrials").prop('checked', false);
  135.                 $("#selSolarsParceles").prop('checked', false);
  136.                 $("#selOportunitatsBancaries").prop('checked', false);
  137.                 $("#desglosPisosCases").hide();
  138.                 $("#desglosLocalsOficines").hide();
  139.                 $("#desglosNausIndustrials").hide();
  140.                 $("#desglosSolarsParceles").hide();
  141.                 $("#desglosParquings").show();
  142.                 $("#titolOrdreHabitacions").hide();
  143.                 $("#selectOrdreHabitacions").hide();
  144.                 visDestacats(5);
  145.                 $.post("<?php echo URL.'includes/inc_getPoblacions.php'?>", {prm:"8"}, function(data){$("#selectCiutatPQ").html(data);});  
  146.             }
  147.             else
  148.                 $("#desglosParquings").hide();
  149.             netejaDetall();
  150.         });
__________________
Qué fácil cuando lo sabes y qué difícil cuando no
  #7 (permalink)  
Antiguo 12/10/2015, 14:59
 
Fecha de Ingreso: enero-2002
Ubicación: Sabadell
Mensajes: 565
Antigüedad: 22 años, 3 meses
Puntos: 4
Respuesta: provocar un evento

Código Javascript:
Ver original
  1. $("#selTotsOp").on('change', function(){
  2.             if ((!$("#selSenseOp").prop('checked')) && (!$("#selNomesOp").prop('checked')))
  3.                 $("#selTotsOp").prop('checked', true);
  4.             else {
  5.                 $("#selNomesOp").prop('checked', false);
  6.                 $("#selSenseOp").prop('checked', false);
  7.                 ob = "0";
  8.                 refresca(op, ob);
  9.             }
  10.         });
  11.  
  12.        
  13.         $("#selSenseOp").on('change', function(){
  14.             if ((!$("#selTotsOp").prop('checked')) && (!$("#selNomesOp").prop('checked')))
  15.                 $("#selSenseOp").prop('checked', true);
  16.             else {
  17.                 $("#selTotsOp").prop('checked', false);
  18.                 $("#selNomesOp").prop('checked', false);
  19.                 ob = "1";
  20.                 refresca(op, ob);
  21.             }
  22.         });
  23.  
  24.         $("#selNomesOp").on('change', function(){
  25.             if ((!$("#selTotsOp").prop('checked')) && (!$("#selSenseOp").prop('checked')))
  26.                 $("#selNomesOp").prop('checked', true);
  27.             else {
  28.                 $("#selTotsOp").prop('checked', false);
  29.                 $("#selSenseOp").prop('checked', false);
  30.                 ob = "2";
  31.                 refresca(op, ob);
  32.             }
  33.         });
  34.        
  35.         $("#checkBarris").on('change', function(){
  36.             if (this.checked)
  37.                 $("#desglosBarris").show();
  38.             else
  39.                 $("#desglosBarris").hide();
  40.         });
  41.        
  42.         $(document).on('change', ".barris", function() {
  43.             tornaBarris()
  44.             refresca(op, ob);
  45.         });
  46.                
  47.         $("#butoRecerca").on('click', function(){
  48.             if ($("#selPisosCases").prop('checked')) {
  49.                 tornaTipusPC();
  50.                 prmCiutat = $("#selectCiutatPC").find("option:selected").val();
  51.                 if (prmCiutat != "")
  52.                     prmCiutat = "U.poblacion = " + prmCiutat;
  53.                 tornaPreu();
  54.                 tornaHabitacions();
  55.                 tornaMetres();
  56.             }
  57.             else if ($("#selLocalsOficines").prop('checked'))
  58.                 tornaTipusLO();
  59.             else if ($("#selNausIndustrials").prop('checked'))
  60.                 prmTipus = "familia = 6";
  61.             else if ($("#selSolarsParceles").prop('checked'))
  62.                 tornaTipusSP();
  63.             else if ($("#selParquings").prop('checked'))
  64.                 prmTipus = "familia = 8"
  65.  
  66.             $.post("<?php echo URL.'includes/inc_getImmobles.php'?>", {prm:op+"-"+ob+"-"+prmTipus+"-"+prmCiutat+"-"+prmPreu+"-"+prmHabitacions+"-"+prmMetres+"-"+prmOrdre+"-"+prmDireccio+"-"+prmBarris}, function(data){  
  67.                 visualitza(data);
  68.             });                        
  69.         });
  70.  
  71.         function visualitza(data) {
  72.             totalI = data.indexOf("$#*");
  73.             totalF = data.indexOf("*#$");
  74.             registres = data.substring(totalI+3, totalF);
  75.             contingut = data.replace("$#*"+registres+"*#$", "");
  76.             $("#contingut").html(contingut);
  77.             if (registres == 9999)
  78.                 $("#totalTrobats").html(destacats);
  79.             else
  80.                 $("#totalTrobats").html("TROBATS: " + registres);
  81.         }
  82.        
  83.         function visDestacats(tipus) {
  84.             switch(tipus) {
  85.                 case 3:
  86.                     destacats = "<label id='destacats'>" + "<?php echo $destacatsPC[$idioma]?>" + "</label>";
  87.                     break;
  88.                 case 5:
  89.                     destacats = "<label id='destacats'>" + "<?php echo $destacatsPQ[$idioma]?>" + "</label>";
  90.                     break;
  91.                 case 6:
  92.                     destacats = "<label id='destacats'>" + "<?php echo $destacatsNI[$idioma]?>" + "</label>";
  93.                     break;
  94.                 case 7:
  95.                     destacats = "<label id='destacats'>" + "<?php echo $destacatsLO[$idioma]?>" + "</label>";              
  96.                     break;
  97.                 case 8:
  98.                     destacats = "<label id='destacats'>" + "<?php echo $destacatsSP[$idioma]?>" + "</label>";              
  99.                     break;
  100.             }
  101.             $.post("<?php echo URL.'includes/inc_getDestacats.php'?>", {prm:tipus}, function(data){
  102.                 visualitza(data);
  103.             });                        
  104.         }
  105.        
  106.         function tornaTipusPC() {
  107.             prmTipus = "";
  108.             i = 0;
  109.             $(".subIndexPC").each(function() {
  110.                 if (this.checked) {
  111.                     if (prmTipus == "")
  112.                         prmTipus = "(";
  113.                     else
  114.                         prmTipus += " or ";
  115.                     prmTipus += "U.tipo = " + pisosCases[i];
  116.                 };
  117.                 i++;
  118.             });
  119.             if (prmTipus != "")
  120.                 prmTipus += ")";
  121.             else
  122.                 prmTipus = "(U.familia = 3 or U.familia = 4)";
  123.         }
__________________
Qué fácil cuando lo sabes y qué difícil cuando no
  #8 (permalink)  
Antiguo 12/10/2015, 14:59
 
Fecha de Ingreso: enero-2002
Ubicación: Sabadell
Mensajes: 565
Antigüedad: 22 años, 3 meses
Puntos: 4
Respuesta: provocar un evento

Código Javascript:
Ver original
  1. function tornaHabitacions() {
  2.             prmHabitacions = "";
  3.             i = 0;
  4.             $(".numHabitacions").each(function() {
  5.                 if (this.checked) {
  6.                     if (prmHabitacions == "")
  7.                         prmHabitacions = "(";
  8.                     else
  9.                         prmHabitacions += " or ";
  10.                     prmHabitacions += "U.habitaciones " + habitacions[i];
  11.                 };
  12.                 i++;
  13.             });
  14.             if (prmHabitacions != "")
  15.                 prmHabitacions += ")";
  16.         }
  17.        
  18.         function tornaPreu() {
  19.             prmPreu = "";
  20.             minim = $("#selectPreuMinPC").find("option:selected").val();
  21.             maxim = $("#selectPreuMaxPC").find("option:selected").val();
  22.             if ((minim != "") && (maxim != ""))
  23.                 prmPreu = "(U.precio >= " + minim*1000 + " AND U.precio <= " + maxim*1000 + ")";
  24.             else if (minim != "")
  25.                 prmPreu = "U.precio >= " + minim*1000;
  26.             else if (maxim != "")
  27.                 prmPreu = "U.precio <= " +maxim*1000;
  28.         }
  29.  
  30.         function tornaMetres() {
  31.             prmMetres = "";
  32.             minim = $("#selectMinMetresPC").find("option:selected").val();
  33.             maxim = $("#selectMaxMetresPC").find("option:selected").val();
  34.             if ((minim != "") && (maxim != ""))
  35.                 prmMetres = "(U.metros >= " + minim + " AND U.metros <= " + maxim + ")";
  36.             else if (minim != "")
  37.                 prmMetres = "U.metros >= " + minim;
  38.             else if (maxim != "")
  39.                 prmMetres = "U.metros <= " +maxim;
  40.         }
  41.        
  42.        
  43.         function tornaTipusLO() {
  44.             prmTipus = "";
  45.             i = 0;
  46.             $(".subIndexLO").each(function() {
  47.                 if (this.checked) {
  48.                     if (prmTipus == "")
  49.                         prmTipus = "(";
  50.                     else
  51.                         prmTipus += " or ";
  52.                     prmTipus += "U.tipo = " + localsOficines[i];
  53.                 };
  54.                 i++;
  55.             });
  56.             if (prmTipus != "")
  57.                 prmTipus += ")";
  58.             else
  59.                 prmTipus = "U.familia = 7";
  60.         }
  61.        
  62.         function tornaTipusSP() {
  63.             prmTipus = "";
  64.             i = 0;
  65.             $(".subIndexSP").each(function() {
  66.                 if (this.checked) {
  67.                     if (prmTipus == "")
  68.                         prmTipus = "(";
  69.                     else
  70.                         prmTipus += " or ";
  71.                     prmTipus += "U.tipo = " + solarsParceles[i];
  72.                 };
  73.                 i++;
  74.             });
  75.             if (prmTipus != "")
  76.                 prmTipus += ")";
  77.             else
  78.                 prmTipus = "U.familia = 5";
  79.         }
  80.        
  81.        
  82.         function tornaBarris() {
  83.             prmBarris = "";
  84.             i = 0;
  85.             arrayBarris = new Array();
  86.             $(".barris").each(function() {
  87.                 if (this.checked)  
  88.                     arrayBarris.push($(this).val());   
  89.             });
  90.             arrayBarris.unique().forEach(function(cp, i) {
  91.                 if (prmBarris == "")
  92.                     prmBarris = "'(";
  93.                 else
  94.                     prmBarris += ",";
  95.                 prmBarris += cp;   
  96.             });
  97.             if (prmBarris != "")
  98.                 prmBarris += ")'";
  99.         }
  100.  
  101.  
  102.         function refresca(op, ob) {
  103.             if (prmBarris == "")
  104.                 barris = "''";
  105.             else
  106.                 barris = prmBarris;
  107.             $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"3"+"-"+op+"-"+ob+"-"+""+"-"+barris}, function(data){$("#totalPisosCases").html("("+data+")");});
  108.             $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"4"+"-"+op+"-"+ob+"-"+"7"+"-"+barris}, function(data){$("#totalLocalsOficines").html("("+data+")");});
  109.             $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"4"+"-"+op+"-"+ob+"-"+"6"+"-"+barris}, function(data){$("#totalNausIndustrials").html("("+data+")");});
  110.             $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"4"+"-"+op+"-"+ob+"-"+"5"+"-"+barris}, function(data){$("#totalSolarsParceles").html("("+data+")");});
  111.             $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"4"+"-"+op+"-"+ob+"-"+"8"+"-"+barris}, function(data){$("#totalParquings").html("("+data+")");});
  112.             if ($("#selPisosCases").prop('checked')) {
  113.                 refrescaDetall(0);
  114.             }
  115.             else if ($("#selLocalsOficines").prop('checked')) {
  116.                 refrescaDetall(1);
  117.             }
  118.             else if ($("#selSolarsParceles").prop('checked')) {
  119.                 refrescaDetall(2);
  120.             }
  121.         }
  122.         function refrescaDetall(opcio) {
  123.             switch (opcio) {
  124.                 case 0:
  125.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"908119896.50019"+"-"+barris}, function(data){$("#totalAtics").html("("+data+")");});
  126.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"897431778.50019"+"-"+barris}, function(data){$("#totalDuplexs").html("("+data+")");});
  127.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"935651163.50019"+"-"+barris}, function(data){$("#totalLofts").html("("+data+")");});
  128.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"3"+"-"+barris}, function(data){$("#totalPisos").html("("+data+")");});
  129.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"949016947.50019"+"-"+barris}, function(data){$("#totalPbs").html("("+data+")");});
  130.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"900892021.50019"+"-"+barris}, function(data){$("#totalTriplexs").html("("+data+")");});
  131.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"4"+"-"+barris}, function(data){$("#totalCases").html("("+data+")");});
  132.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"299136542.50019"+"-"+barris}, function(data){$("#totalCasesC").html("("+data+")");});
  133.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"935170816.50019"+"-"+barris}, function(data){$("#totalCasesI").html("("+data+")");});
  134.                 break;
  135.                 case 1:
  136.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"7"+"-"+barris}, function(data){$("#totalLocalC").html("("+data+")");});
  137.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"218592849.50019"+"-"+barris}, function(data){$("#totalLocalI").html("("+data+")");});
  138.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"877918607.50019"+"-"+barris}, function(data){$("#totalOficina").html("("+data+")");});
  139.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"329189847.50019"+"-"+barris}, function(data){$("#totalRestaurant").html("("+data+")");});
  140.                 break;
  141.                 case 2:
  142.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"5"+"-"+barris}, function(data){$("#totalSolar").html("("+data+")");});
  143.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"880782203.50019"+"-"+barris}, function(data){$("#totalSolarI").html("("+data+")");});
  144.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"884930416.50019"+"-"+barris}, function(data){$("#totalSolarO").html("("+data+")");});
  145.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"932673848.50019"+"-"+barris}, function(data){$("#totalSolarP").html("("+data+")");});
  146.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"463133863.50019"+"-"+barris}, function(data){$("#totalSolarPR").html("("+data+")");});
  147.                     $.post("<?php echo URL.'includes/inc_getInfo.php'?>", {prm:"5"+"-"+op+"-"+ob+"-"+"954401543.50019"+"-"+barris}, function(data){$("#totalSolarR").html("("+data+")");});
  148.                 break;
  149.             }
  150.         }
  151.  
  152.         function netejaDetall() {
  153.             prmTipus = ""; prmCiutat = ""; prmPreu = ""; prmHabitacions = ""; prmMetres = "";      
  154.             $('.subIndexPC').each(function() {
  155.                 $(this).prop("checked", false);
  156.             });
  157.             $('.subIndexLO').each(function() {
  158.                 $(this).prop("checked", false);
  159.             });
  160.             $('.subIndexSP').each(function() {
  161.                 $(this).prop("checked", false);
  162.             });
  163.             $('.selectCiutat').val('');
  164.             $('.selectMin').val('');
  165.             $('.selectMax').val('');
  166.         }
  167.        
  168.         function netejaSelectOrdre(ordre) {
  169.             if (ordre != "#selectOrdrePreu") {
  170.                 $("#selectOrdrePreu").val(0);
  171.                 $("#selectOrdrePreu").css('width', '30px');
  172.             }
  173.             if (ordre != "#selectOrdreM2") {
  174.                 $("#selectOrdreM2").val(0);
  175.                 $("#selectOrdreM2").css('width', '30px');
  176.             }
  177.             if (ordre != "#selectOrdreHabitacions") {
  178.                 $("#selectOrdreHabitacions").val(0);
  179.                 $("#selectOrdreHabitacions").css('width', '30px');
  180.             }
  181.             if (ordre != "#selectOrdreCiutat") {
  182.                 $("#selectOrdreCiutat").val(0);    
  183.                 $("#selectOrdreCiutat").css('width', '30px');
  184.             }      
  185.         }
  186.     });
  187. </script>
__________________
Qué fácil cuando lo sabes y qué difícil cuando no
  #9 (permalink)  
Antiguo 12/10/2015, 15:43
Avatar de Trublux  
Fecha de Ingreso: octubre-2010
Ubicación: Madrid
Mensajes: 355
Antigüedad: 13 años, 6 meses
Puntos: 48
Respuesta: provocar un evento

Tienes que poner el trigger después (lo que puse en el OJO).
__________________
eZ Publish Developer Basic Legacy
eZ Publish Developer Basics (4.4)
Alojamientos rurales en España
  #10 (permalink)  
Antiguo 12/10/2015, 16:12
 
Fecha de Ingreso: enero-2014
Ubicación: Navarra
Mensajes: 94
Antigüedad: 10 años, 4 meses
Puntos: 18
Respuesta: provocar un evento

Hola.

La consola me indica que falta un cierre });
se lo he añadido antes del cierre de la etiqueta </script> y parece que funciona

no se si ha sido un error al copiar y pegar aqui.

Tambien he añadido un <?php $_tipus = 3; ?> para poder probar

Has revisado el codigo generado para ver si realmente recibes bien el valor de $_tipos ?

La vedad es que no veo errores a no ser que lo tengas en el html con dos id con el mismo nombe o algo asi.

Siento no poder darte mas pistas, pero es que lo veo todo correcto.
Saludos.
  #11 (permalink)  
Antiguo 12/10/2015, 16:19
 
Fecha de Ingreso: enero-2002
Ubicación: Sabadell
Mensajes: 565
Antigüedad: 22 años, 3 meses
Puntos: 4
Respuesta: provocar un evento

Gracias Trublux, he puesto el trigger al final y funciona.
De nuevo muchas gracias
__________________
Qué fácil cuando lo sabes y qué difícil cuando no

Etiquetas: evento
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 06:00.