Foros del Web » Programando para Internet » Javascript » Frameworks JS »

Solo modifique pero falta algo

Estas en el tema de Solo modifique pero falta algo en el foro de Frameworks JS en Foros del Web. Buenas....tengo este formulario doble...hasta ahora va bien... pero necesito que se pueda borrar los campo agregados, limitar el numero de agregados y colocar un text ...
  #1 (permalink)  
Antiguo 20/09/2010, 11:15
Avatar de RucarMaN  
Fecha de Ingreso: julio-2003
Ubicación: Caripito Edo Monagas
Mensajes: 169
Antigüedad: 20 años, 9 meses
Puntos: 1
Solo modifique pero falta algo

Buenas....tengo este formulario doble...hasta ahora va bien...
pero necesito que se pueda borrar los campo agregados, limitar el numero de agregados y colocar un text al fina donde me pueda sumar los precios..
Código HTML:
Ver original
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2.  
  3. <html>
  4. <head>
  5.     <title>Presupuesto</title>
  6.     <script src="jquery-1.4.1.min.js" type="text/javascript"></script>
  7.     <script>
  8.     jQuery.fn.generaMO = function(etiquetaMO, nombreCampoMO, indiceMO){
  9.         $(this).each(function(){
  10.             elem = $(this);
  11.             elem.data("etiquetaMO",etiquetaMO);
  12.             elem.data("nombreCampoMO",nombreCampoMO);
  13.             elem.data("indiceMO",indiceMO);
  14.            
  15.             elem.click(function(MO){
  16.                 MO.preventDefault();
  17.                 elem = $(this);
  18.                 etiquetaMO = elem.data("etiquetaMO");
  19.                 nombreCampoMO = elem.data("nombreCampoMO");
  20.                 indiceMO = elem.data("indiceMO");
  21.                 //texto_insertarMO = + etiquetaMO + ' ' + indiceMO + ':<input type="text" name="454554" /></p>';
  22.                 texto_insertarMO = '<input type="text" name="manoObra" size="50" /><input type="text" name="precioMO" size="5" /><br />';
  23.                 indiceMO ++;
  24.                 elem.data("indiceMO",indiceMO);
  25.                 nuevo_campoMO = $(texto_insertarMO);
  26.                 elem.before(nuevo_campoMO);
  27.             });
  28.         });
  29.         return this;
  30.     }
  31.     $(document).ready(function(){
  32.         $("#masMO").generaMO("Compra", "compra", 2);
  33.     });
  34.    
  35.     jQuery.fn.generaRE = function(etiquetaRE, nombreCampoRE, indiceRE){
  36.         $(this).each(function(){
  37.             elem = $(this);
  38.             elem.data("etiquetaRE",etiquetaRE);
  39.             elem.data("nombreCampoRE",nombreCampoRE);
  40.             elem.data("indiceRE",indiceRE);
  41.            
  42.             elem.click(function(RE){
  43.                 RE.preventDefault();
  44.                 elem = $(this);
  45.                 etiquetaRE = elem.data("etiquetaRE");
  46.                 nombreCampoRE = elem.data("nombreCampoRE");
  47.                 indiceRE = elem.data("indiceRE");
  48.                 //texto_insertar = '<p>' + etiqueta + ' ' + indice + ':<br><input type="text" name="' + nombreCampo + indice + '" /></p>';
  49.                 texto_insertarRE = '<input type="text" name="cant" size="2" /><input type="text" name="repuesto" size="50" /><input type="text" name="precioRE" size="5" /><br />';
  50.                 indiceRE ++;
  51.                 elem.data("indiceRE",indiceRE);
  52.                 nuevo_campoRE = $(texto_insertarRE);
  53.                 elem.before(nuevo_campoRE);
  54.             });
  55.         });
  56.         return this;
  57.     }
  58.     $(document).ready(function(){
  59.         $("#masRE").generaRE("Compra", "compra", 2);
  60.     });
  61.    
  62.     </script>
  63. </head>
  64.  
  65. <body>
  66. <table width="100%" border="0">
  67.   <tr valign="top">
  68.     <td><!--<input type="Text" name="manoObra" size="50"><input type="text" name="precioMO" size="5" /><br>-->
  69.  
  70.      <a href="#" id="masMO">Mano de Obra</a></td>
  71.     <td><!---<input type="text" name="cant" size="2" /><input type="Text" name="repuesto" size="50"><input type="text" name="precioRE" size="5" /><br>-->
  72.  
  73.      <a href="#" id="masRE">Repuesto</a></td>
  74.   </tr>
  75. <!--
  76. <input type="Text" name="compra" size="50"><input type="text" name="precio" size="5" /><br />
  77. <a href="#" id="mascampos">Más campos</a> -->
  78. <p><input type=submit value="   Guardar   " /> </p>
  79. </form>
  80.  <a href="add2.html">home</a>
  81. </body>
  82. </html>

tomado de http://www.desarrolloweb.com/articul...ormulario.html
tengo este otro....esto borra los campos agregados
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  2.  
  3. <html>
  4. <title>Crear input file</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  6. <script type="text/javascript">
  7. <!--
  8. num=0;
  9. function crear(obj) {
  10.  num++;
  11.  fi = document.getElementById('fiel'); // 1
  12.  contenedor = document.createElement('div'); // 2
  13.  contenedor.id = 'div'+num; // 3
  14.  fi.appendChild(contenedor); // 4
  15.  
  16.  ele = document.createElement('input'); // 5
  17.  ele.type = 'text'; // 6
  18.  //ele.name = 'fil'+num; // 6
  19.  ele.name = 'NombreRepuesto';
  20.  ele.size = '60';
  21.  contenedor.appendChild(ele); // 7
  22.  
  23.   ele = document.createElement('input'); // 5
  24.  ele.type = 'checkbox'; // 6
  25.  //ele.name = 'fil'+num; // 6
  26.  ele.name = 'eliminar';
  27.  ele.value = 'ON';
  28.  contenedor.appendChild(ele); // 7
  29.  
  30.  ele = document.createElement('input'); // 5
  31.  ele.type = 'button'; // 6
  32.  ele.value = ' X '; // 8
  33.  ele.name = 'div'+num; // 8
  34.  ele.onclick = function () {borrar(this.name)} // 9
  35.  contenedor.appendChild(ele); // 7
  36. }
  37. function borrar(obj) {
  38.  fi = document.getElementById('fiel'); // 1
  39.  fi.removeChild(document.getElementById(obj)); // 10
  40. }
  41. -->
  42. </head>
  43. <form method="get" action="algo.asp">
  44. <p id="fiel">
  45. <input type="button" value="Crear" onclick="crear(this)" />
  46. </p>
  47. <input type=submit value=grabar>
  48. </form>
  49. </body>
  50. </html>
__________________
Con la ayuda de todos seremos mejores...

http://www.pemoweb.com

Última edición por RucarMaN; 20/09/2010 a las 11:40
  #2 (permalink)  
Antiguo 20/09/2010, 15:50
Avatar de caricatos
Moderador
 
Fecha de Ingreso: abril-2002
Ubicación: Torremolinos (Málaga)
Mensajes: 19.607
Antigüedad: 22 años
Puntos: 1284
Tema movido desde javascript
__________________
Por favor:
No hagan preguntas de temas de foros en mensajes privados... no las respondo
  #3 (permalink)  
Antiguo 20/09/2010, 18:34
 
Fecha de Ingreso: diciembre-2009
Ubicación: Misiones
Mensajes: 867
Antigüedad: 14 años, 4 meses
Puntos: 65
Respuesta: Solo modifique pero falta algo

pero con jquery? ahi veo que el primero es con jquery y el segundo con javascript puro

con jquery es bastante sencillo, claro, mínimo una lectura a la documentación (yo no sé inglés pero viendo los ejemplos se nota que hace)

buscá en la doc que hace cada método, lo que usé se ocupa todos los días

es simple pero con más campos es lo mismo, click en borrar sube hasta el div padre con class 'linea' y borra ese div, click en agregar agrega al div #contenedor la cadena que contiene html en la variable linea
por eso si agregas inputs va a ser lo mismo

para sumar tengo la funcion que selecciono los campos cantidad, sumo y muestro el valor en el input total, esa funcion la meto en el evento cuando se borra un campo para que me vuelva a calcular

Código HTML:
Ver original
  1.   <head>
  2.     <title></title>
  3.     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4.     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
  5.     <script>
  6.     $( function (){
  7.         var limite = 5;
  8.         var linea = '<div class="linea">Precio: <input type="text" class="cantidad" name="cantidad" /><a href="#" class="borra">Eliminar</a></div>';
  9.  
  10.         $('#agrega').live('click', function (){
  11.             if ( $('#contenedor .linea').length < limite)
  12.                $('#contenedor').append(linea);
  13.        });
  14.        
  15.        $('#contenedor .borra').live('click', function(){
  16.            $(this).closest('.linea').remove();
  17.            calcularTotal();
  18.        });
  19.  
  20.        $('#contenedor input.cantidad').live('keyup', function(){
  21.            calcularTotal();
  22.        });
  23.    });
  24.  
  25.    function calcularTotal(){
  26.        var total = parseInt(0);
  27.        $('#contenedor input.cantidad[value!=""]').each( function (){
  28.            total += parseInt( $(this).val() );
  29.        });
  30.        $('#total').val(total);
  31.    }
  32.    </script>
  33.   </head>
  34.   <style>
  35.       #contenedor{margin-bottom:10px;}
  36.       #contenedor .linea{margin-bottom:5px; background:#ccc; width:250px; padding:3px}
  37.   </style>
  38.     <div id="contenedor"></div>
  39.     <a href="#" id="agrega">Agregar</a><br />
  40.     Total: <input type="text" name="total" id="total" />
  41. </body>
  42. </html>
  #4 (permalink)  
Antiguo 21/09/2010, 11:28
Avatar de RucarMaN  
Fecha de Ingreso: julio-2003
Ubicación: Caripito Edo Monagas
Mensajes: 169
Antigüedad: 20 años, 9 meses
Puntos: 1
Respuesta: Solo modifique pero falta algo

Dany_s...esta esta de lujo.....gracias.... pero, nunca falta el bendito pero....
le agregue mas campos texto..[pieza] - [cantidad] x [precio unitario] = [subtotal]
necesito que multiplique cantidad*precio unitario y resultado en subtotal y luego gran total...
es para realizar una cotización...
PD: sera que se endiente???
__________________
Con la ayuda de todos seremos mejores...

http://www.pemoweb.com

Etiquetas: falta
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 15:14.