Ver Mensaje Individual
  #2 (permalink)  
Antiguo 19/05/2012, 20:22
Avatar de cristian_cena
cristian_cena
Colaborador
 
Fecha de Ingreso: junio-2009
Mensajes: 2.244
Antigüedad: 15 años, 8 meses
Puntos: 269
Respuesta: como recuperar los valores de varios campos con javascript

no se bien que intentas hacer. fijate si algo asi te sirve:

Código HTML:
Ver original
  1. <input type='text' name='campo1' value='valor0'/>
  2. <input type='text' name='campo2' value='valor1'/>
  3. <input type='text' name='campo3' value='valor2'/>
  4. <div id="out"></div>

Código Javascript:
Ver original
  1. //imprimimos el value de todos los inputs
  2. function getAllValueInputs(){
  3.     var inputs = document.getElementsByTagName("input");
  4.     var out = document.getElementById("out");
  5.     for(var i = 0; i<inputs.length; i++){
  6.         if(inputs[i].type == "text"){
  7.             out.innerHTML += inputs[i].value + "</br>";
  8.         }
  9.     }
  10. }
  11. //imprimimos el value del input pasado a la funcion.
  12. function getValueInput(inp){
  13.     var inputs = document.getElementsByTagName("input");
  14.     var out = document.getElementById("out");
  15.     for(var i = 0; i<inputs.length; i++){
  16.         if(inputs[i].type == "text"){
  17.             if(inputs[i].name == inp){
  18.                 out.innerHTML += inputs[i].value + "</br>";
  19.             }
  20.         }
  21.     }
  22. }
  23. window.onload = function(){
  24.     getAllValueInputs();
  25.     getValueInput("campo2"); //pasas como argumento el valor del atributo name
  26. }


Saludos