Foros del Web » Programando para Internet » Javascript »

Validar tabla dinamica

Estas en el tema de Validar tabla dinamica en el foro de Javascript en Foros del Web. Espero me puedan ayudar Código PHP: function  agregar_fila ( origen , destino ) {      ///////////////////////////////////////////      var  region    =  origen . regiones . value ; ...
  #1 (permalink)  
Antiguo 22/11/2008, 14:09
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Validar tabla dinamica

Espero me puedan ayudar
Código PHP:
function agregar_fila(origen,destino) {
    
///////////////////////////////////////////

    
var region   origen.regiones.value;
    var 
territorio origen.territorio.value;
    var 
provincia origen.provincia.value;
    var 
comuna origen.comuna.value;
    var 
localidad origen.value;
    
    var 
nuevo_indice destino.rows.length;

    var 
fila;
    var 
celda;
    var 
valor;
    
    
fila destino.insertRow(nuevo_indice);
    
fila.style.background "white";
    
    
///////////////////////////////////////////

    
celda fila.insertCell(0);
    
valor document.createElement("input");
        
valor.type "checkbox";
        
valor.id "marca[]";
        
valor.name "marca[]";
        
valor.value nuevo_indice;
    
celda.appendChild(valor);

    
///////////////////////////////////////////

    
celda fila.insertCell(1);
    var 
region document.createElement('input'
        
region.type 'hidden'

    
var region_id document.getElementById('regiones');
        var 
txtTextObj document.getElementById('txtText');
        
    var 
selIndex region_id.selectedIndex;
        
region.value region_id.options[selIndex].text;    

    
valor document.createTextNode(region.value);
    
celda.appendChild(valor);
    
    
///////////////////////////////////////////

    
celda fila.insertCell(2);
    var 
territorio document.createElement('input'
        
territorio.type 'hidden'

    
var territorio_id document.getElementById('territorio');
        var 
txtTextObj document.getElementById('txtText');

    var 
selIndex territorio_id.selectedIndex;
        
territorio.value territorio_id.options[selIndex].text;    

    
valor document.createTextNode(territorio.value);
    
celda.appendChild(valor);
    
    
///////////////////////////////////////////

    
celda fila.insertCell(3);
    var 
provincia document.createElement('input'
        
provincia.type 'hidden'

    
var provincia_id document.getElementById('provincia');
        var 
txtTextObj document.getElementById('txtText');

    var 
selIndex provincia_id.selectedIndex;
        
provincia.value provincia_id.options[selIndex].text;    

    
valor document.createTextNode(provincia.value);
    
celda.appendChild(valor);
    
    
///////////////////////////////////////////

    
celda fila.insertCell(4);
    var 
comuna document.createElement('input'
        
comuna.type 'hidden'

    
var comuna_id document.getElementById('comuna');
        var 
txtTextObj document.getElementById('txtText');


    var 
selIndex comuna_id.selectedIndex;
        
comuna.value comuna_id.options[selIndex].text;

    
valor document.createTextNode(comuna.value);
    
celda.appendChild(valor);

    
///////////////////////////////////////////

    
celda fila.insertCell(5);

    var 
localidad document.createElement('input')
        
localidad.type 'hidden'
        
localidad.name 'localidad[]'

    
var localidad_id document.getElementById('localidad');
        var 
txtTextObj document.getElementById('txtText');

    var 
selIndex localidad_id.selectedIndex;
        
localidad.value localidad_id.options[selIndex].text;

    
valor document.createTextNode(localidad.value);
    
celda.appendChild(valor);

    
///////////////////////////////////////////

    
celda fila.insertCell(6);

    var 
localidad_value document.getElementById('localidad');
    var 
selIndex localidad_value.selectedIndex;
    var 
val localidad_value.options[selIndex].value;
    
valores val.split(',')

    var 
latitud document.createElement('input'// latitud
        
latitud.type 'text'
        
latitud.name 'latitud[]'
        
latitud.id 'latitud'
        
latitud.onblur coordenadas_1;
        
latitud.onkeypress numeros_dom;
        
latitud.value valores[1]
        if (
valores[1] != '') {
        
latitud.readOnly true
        
}

        
celda.appendChild(latitud);

    
///////////////////////////////////////////

    
celda fila.insertCell(7);

    var 
localidad_value document.getElementById('localidad');
    var 
selIndex localidad_value.selectedIndex;
    var 
val localidad_value.options[selIndex].value;
    
valores val.split(',')

    var 
longitud document.createElement('input'// longitud
        
longitud.type 'text'
        
longitud.name 'longitud[]'
        
longitud.id 'longitud'
        
longitud.onkeypress numeros_dom;
        
longitud.value valores[2]
        if (
valores[2] != '') {
        
longitud.readOnly true
        
}

        
celda.appendChild(longitud);

    
///////////////////////////////////////////

    
celda fila.insertCell(8);
    var 
monto document.createElement('input'// montos
        
monto.type 'text'
        
monto.name 'montos[]'
        
monto.setAttribute('class''required')
        
monto.title 'Ingrese el monto asignado'
        
monto.onkeypress numeros_dom;

        
celda.appendChild(monto);

    
///////////////////////////////////////////

    
var    region document.createElement('input'// regiones
        
region.type 'hidden'
        
region.name 'regiones[]'

    
var region_id document.getElementById('regiones');
        var 
txtidObj document.getElementById('txtid');

    var 
selIndex region_id.selectedIndex;
        
region.value region_id.options[selIndex].id;

        
celda.appendChild(region);

    
///////////////////////////////////////////

    
var    territorio document.createElement('input'// territorio
        
territorio.type 'hidden'
        
territorio.name 'territorios[]'

    
var territorio_id document.getElementById('territorio');
        var 
txtidObj document.getElementById('txtid');

    var 
selIndex territorio_id.selectedIndex;
        
territorio.value territorio_id.options[selIndex].id;

        
celda.appendChild(territorio);

    
///////////////////////////////////////////

    
var    provincia document.createElement('input'// territorio
        
provincia.type 'hidden'
        
provincia.name 'provincias[]'

    
var provincia_id document.getElementById('provincia');
        var 
txtidObj document.getElementById('txtid');

    var 
selIndex provincia_id.selectedIndex;
        
provincia.value provincia_id.options[selIndex].id;

        
celda.appendChild(provincia);

    
///////////////////////////////////////////

    
var    comuna document.createElement('input'// territorio
        
comuna.type 'hidden'
        
comuna.name 'comunas[]'

    
var comuna_id document.getElementById('comuna');
        var 
txtidObj document.getElementById('txtid');

    var 
selIndex comuna_id.selectedIndex;
        
comuna.value comuna_id.options[selIndex].id;

        
celda.appendChild(comuna);

    
///////////////////////////////////////////

    
var localidad_value document.getElementById('localidad');
    var 
selIndex localidad_value.selectedIndex;
    var 
val localidad_value.options[selIndex].value;
    
valores val.split(',')

    var 
localidad document.createElement('input')
        
localidad.type 'hidden'
        
localidad.name 'localidades[]'
        
localidad.value valores[0]

        
celda.appendChild(localidad);


Código PHP:
function coordenadas_1() {

inputed=document.getElementById('latitud["+marca[]+"]');
a=inputed.value;
alert(a);

Código PHP:
 <button type="button" name="boton" id="boton" onClick="agregar_fila(form,info)" disabled=true >Agregar</button>
  <
button type="button" onClick="remover_filas_marcadas(info)">Remover</button>

<
table class="ensayo" id="info" name="info">
<
tr class="titulos">
    <
td>&nbsp;</td>
    <
td>Region</td>
    <
td>Territorio</td>
    <
td>Provincia</td>
    <
td>Comuna</td>
    <
td>Localidad</td>
    <
td>Latitud</td>
    <
td>Longitud</td>
    <
td>Monto</td>
</
tr>
</
table
Salu2
  #2 (permalink)  
Antiguo 22/11/2008, 14:15
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Respuesta: Validar tabla dinamica

Hola vmac179

¿Ayudarte a qué?

Saludos,
  #3 (permalink)  
Antiguo 22/11/2008, 14:45
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Validar tabla dinamica

con la funcion coordenadas_1()

Código PHP:

function coordenadas_1() {

inputed=document.getElementById('latitud["+marca[]+"]');
a=inputed.value;
alert(a);

no me esta validando

Última edición por vmac179; 22/11/2008 a las 15:30
  #4 (permalink)  
Antiguo 22/11/2008, 15:51
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Validar tabla dinamica

a ver, si la funcion la dejo de esta manera

Código PHP:
function coordenadas_1() {

var 
latitud document.getElementById('latitud').value;
alert latitud )

me arroja solamente el valor de la primera columna, lo que no se como hacer es para que me valide todas las que se van creando
  #5 (permalink)  
Antiguo 22/11/2008, 16:56
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Validar tabla dinamica

Es que estás asignando un mismo id "marca[]", a todos los que se van creando. El id debe ser único en el documento. Además, lo de latitud en el getElementById no termino de entender por qué lo pones.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #6 (permalink)  
Antiguo 22/11/2008, 19:59
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Validar tabla dinamica

lo que necesito hacer es validar el campo latitud que se va creando dinamicamente, osea todos los campo latitud que se van creando, llevan el mismo id, y name es por eso que van con corchetes [] porque después los separo en un bucle for y los añado a la BD.

Salu2
  #7 (permalink)  
Antiguo 22/11/2008, 20:04
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Validar tabla dinamica

Pero el id, NO DEBE estar repetido. No debes tener dos elementos con el mismo id en el documento. Además, ni en el id ni el name estás agregando "latitud":
Código javascript:
Ver original
  1. valor.id = "marca[]";
  2. valor.name = "marca[]";
El name sí puede estar repetido, con eso no hay problema, pero el id no se debe. Además, los corchetes no son necesarios en el id, puedes asignar un número sucesivo al id de cada elemento creado, por ejemplo, marca1, marca2, marca3...
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #8 (permalink)  
Antiguo 22/11/2008, 20:34
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Validar tabla dinamica

y si los quiero validar antes de enviar ??
  #9 (permalink)  
Antiguo 22/11/2008, 20:54
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Validar tabla dinamica

Puedes usar el evento onsubmit del formulario, recorrer todos los objetos con ese name en un bucle for y validarlos.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #10 (permalink)  
Antiguo 22/11/2008, 22:32
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Validar tabla dinamica

y como sería ??? si me puedes dar un consejo por favor
  #11 (permalink)  
Antiguo 22/11/2008, 22:43
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Validar tabla dinamica

Fíjate en este ejemplo:
Código javascript:
Ver original
  1. elems = document.formulario["nombre[]"];
  2. for (i=0; elem=elems[i]; i++) {
  3.     alert(elem.value);
  4. }
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #12 (permalink)  
Antiguo 23/11/2008, 09:13
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Validar tabla dinamica

simplemente
gracias totales
  #13 (permalink)  
Antiguo 23/11/2008, 10:05
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Validar tabla dinamica

Hola otra vez, disculpen mis dudas dudosas, pero tengo el siguiente problema

Código PHP:
    var cuantas document.getElementById('info').rows.length// cuento las filas
    
var total cuantas-1// le resto la fila de los titulos
    
var latitud document.getElementById['latitud[]'];
    var 
lat document.getElementById('latitud[]');

        if (
total == 1) {            
            
alert (lat.value);        
        }  
        if (
total != 1) {
            for (
i=0latitud=latitud[i]; i++) {
            
alert(latitud.value);
            }
        } 
Solo funciona cuando tengo una fila, pero si tengo dos se cae en el for, espero me puedan ayudar

Salu2 y gracias por toda su ayuda y compresión
  #14 (permalink)  
Antiguo 23/11/2008, 10:08
Avatar de JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 2 meses
Puntos: 772
Respuesta: Validar tabla dinamica

Hola vmac179

Me parece que estás usando latitud como un array, pero no es un array porque getElementById sólo devuelve un elemento.

Saludos,
  #15 (permalink)  
Antiguo 23/11/2008, 10:10
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: Validar tabla dinamica

Tal y como te dice JavierB y como te estoy diciendo desde el primer mensaje :, no debes tener varios elementos con el mismo id, con getElementById solo obtendrás un elemento. El ejemplo que te coloqué en el mensaje anterior era con elementos que tuviesen el name igual.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #16 (permalink)  
Antiguo 23/11/2008, 10:31
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Validar tabla dinamica

Arreglado
Código PHP:
    var cuantas document.getElementById('info').rows.length// cuento las filas
    
var total cuantas-1// le resto la fila de los titulos
    
var lat document.getElementById('latitud');            
    var 
latitud document.form['latitud[]'];

        if (
total == 1) {
            
alert (lat.value);        
        }  
        if (
total != 1) {
            for (
i=0lat=latitud[i]; i++) {
            
alert(lat.value);
            }
        } 
Simplemente gracias totales amigos
  #17 (permalink)  
Antiguo 23/11/2008, 13:15
 
Fecha de Ingreso: julio-2007
Ubicación: /home/victor
Mensajes: 114
Antigüedad: 16 años, 9 meses
Puntos: 0
Respuesta: Validar tabla dinamica

Solucion a problema en IE

Código PHP:
function coordenadas() {

    var 
cuantas document.getElementById('info').rows.length// cuento las filas
    
var total cuantas-1// le resto la fila de los titulos

        
if (total == 1) {
            var 
lat document.getElementById('latitud'); // document.getElementById devuelve solamente un elemento                    
            
alert (lat.value);
        }  
        
        else if (
total != 1) {
            var 
latitud document.form["latitud"];
            for (
i=0lat=latitud[i]; i++) {
            
alert(lat.value);
            }
        }  



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 22:51.