Ver Mensaje Individual
  #2 (permalink)  
Antiguo 14/09/2012, 00:52
quimfv
Colaborador
 
Fecha de Ingreso: marzo-2008
Ubicación: Sabadell
Mensajes: 4.897
Antigüedad: 17 años
Puntos: 574
Respuesta: Interrumpir funcion al llegar al maximo contador

Código Javascript:
Ver original
  1. function adicionarFila(){
  2.     //LIMITADO A 12 MÁXIMO
  3.     if(tabla.getElementsByTagName("tr").length>=12) {
  4.         alert('YA NO ES POSIBLE AGREGAR MAS FILAS')
  5.         return false;
  6.     }else{
  7.         var cont = document.getElementById("cont");
  8.         var filas = document.getElementById("filas");
  9.         cont.setAttribute("value", parseInt(cont.value,0)+1);
  10.         var tabla = document.getElementById("contenido").tBodies[0];
  11.         var fila = document.createElement("TR");
  12.         fila.setAttribute("align","left");
  13.  
  14.         var celda1 = document.createElement("TD");
  15.         var sel = document.createElement("SELECT");
  16.         sel.setAttribute("size","1");
  17.         sel.setAttribute("name","produc" + cont.value);
  18.         sel.setAttribute("ID","sel");
  19.         opcioncur = document.createElement("OPTION");
  20.         opcioncur.innerHTML = 'Zapato';
  21.         opcioncur.value = 'Zapato';
  22.         sel.appendChild(opcioncur);
  23.  
  24.     celda1.appendChild(sel);
  25.    
  26.     var celda2 = document.createElement("TD");
  27.     var sel = document.createElement("SELECT");
  28.     sel.setAttribute("size","1");
  29.     sel.setAttribute("name","color" + cont.value);
  30.     opcioncur = document.createElement("OPTION");
  31.     opcioncur.innerHTML = 'Verde';
  32.     opcioncur.value = 'verde';
  33.     sel.appendChild(opcioncur);
  34.    
  35.     opcion1 = document.createElement("OPTION");
  36.     opcion1.innerHTML = "Rojo";
  37.     opcion1.value = "rojo";
  38.     sel.appendChild(opcion1);
  39.  
  40.     opcion2 = document.createElement("OPTION");
  41.     opcion2.innerHTML = "Fucsia";
  42.     opcion2.value = "fucsia";
  43.     sel.appendChild(opcion2);
  44.  
  45.     opcion3 = document.createElement("OPTION");
  46.     opcion3.innerHTML = "Naranja";
  47.     opcion3.value = "naranja";
  48.     sel.appendChild(opcion3);
  49.     celda2.appendChild(sel);
  50.    
  51.     opcion4 = document.createElement("OPTION");
  52.     opcion4.innerHTML = "Blanco";
  53.     opcion4.value = "blanco";
  54.     sel.appendChild(opcion4);
  55.     celda2.appendChild(sel);
  56.    
  57.     opcion5 = document.createElement("OPTION");
  58.     opcion5.innerHTML = "Negro";
  59.     opcion5.value = "negro";
  60.     sel.appendChild(opcion5);
  61.     celda2.appendChild(sel);
  62.    
  63.     opcion6 = document.createElement("OPTION");
  64.     opcion6.innerHTML = "Amarillo";
  65.     opcion6.value = "amarillo";
  66.     sel.appendChild(opcion6);
  67.     celda2.appendChild(sel);
  68.  
  69.     var celda3 = document.createElement("TD");
  70.     var sel = document.createElement("SELECT");
  71.     sel.setAttribute("size","1");
  72.     sel.setAttribute("name","talla" + cont.value);
  73.     opcioncur = document.createElement("OPTION");
  74.     opcioncur.innerHTML = '36';
  75.     opcioncur.value = '36';
  76.     sel.appendChild(opcioncur);
  77.    
  78.     opcion1 = document.createElement("OPTION");
  79.     opcion1.innerHTML = "37";
  80.     opcion1.value = "37";
  81.     sel.appendChild(opcion1);
  82.    
  83.     opcion2 = document.createElement("OPTION");
  84.     opcion2.innerHTML = "38";
  85.     opcion2.value = "38";
  86.     sel.appendChild(opcion2);
  87.    
  88.     opcion3 = document.createElement("OPTION");
  89.     opcion3.innerHTML = "39";
  90.     opcion3.value = "39";
  91.     sel.appendChild(opcion3);
  92.     celda3.appendChild(sel);
  93.    
  94.     opcion4 = document.createElement("OPTION");
  95.     opcion4.innerHTML = "40";
  96.     opcion4.value = "40";
  97.     sel.appendChild(opcion4);
  98.     celda3.appendChild(sel);
  99.  
  100.     var celda4 = document.createElement("TD");
  101.     var valorb = document.createElement("INPUT");
  102.     celda4.align = ("center");
  103.     valorb.setAttribute("type","text");
  104.     valorb.setAttribute("border","none");
  105.     valorb.setAttribute("size","2");
  106.     valorb.setAttribute("maxlength","2");
  107.     valorb.setAttribute("name","canti" + cont.value);
  108.     valorb.className=("listo");
  109.     valorb.value = "1";
  110.     celda4.appendChild(valorb);
  111.    
  112.     var celda5 = document.createElement("TD");
  113.     var valorc = document.createElement("INPUT");
  114.     celda5.align = ("center");
  115.     valorc.setAttribute("type","text");
  116.     valorc.setAttribute("border","none");
  117.     valorc.setAttribute("size","5");
  118.     valorc.setAttribute("maxlength","2");
  119.     valorc.setAttribute("name","pre" + cont.value);
  120.     valorc.className=("listo");
  121.     valorc.value = "100 Bs";
  122.     celda5.appendChild(valorc);  
  123.    
  124.     var celda6 = document.createElement('TD');
  125.     var boton = document.createElement('INPUT');
  126.     celda6.align=("left")
  127.     boton.setAttribute('type','button');
  128.     boton.setAttribute('value','borrar');
  129.     boton.onclick=function(){borrarFila(this);add(-1);add2(-100)}
  130.     boton.className=("boton")
  131.     celda6.appendChild(boton);
  132.    
  133.    
  134.     fila.appendChild(celda1);
  135.     fila.appendChild(celda2);
  136.     fila.appendChild(celda3);
  137.     fila.appendChild(celda4);
  138.     fila.appendChild(celda5);
  139.     fila.appendChild(celda6);
  140.    
  141.     tabla.appendChild(fila);
  142.    
  143.     }
  144. }

Solo he modificado la función adicionarFila(). (Ojo con el doble cierre al final }})
__________________
Quim
--------------------------------------------------
Ayudar a ayudar es una buena práctica!!! Y da buenos resultados.