Foros del Web

Foros del Web (http://www.forosdelweb.com/)
-   Frameworks JS (http://www.forosdelweb.com/f127/)
-   -   consulta dom (http://www.forosdelweb.com/f127/consulta-dom-599924/)

anion0x 25/06/2008 08:13

consulta dom
 
Tengo la siguiente tabla:

Código:

        <div class="bottomLine">
                        <table id="tabla">
              <tr>
                <th><label for="secundario">Título Secundario</label></th>
                <td><input type="text" name="secundario" id="secundario" value="<?=v('secundario')?>" /></td>
                <th><label for="institucion">Institución</label></th>
                <td><input type="text" name="institucion" id="institucion" value="<?=v('institucion')?>" /></td>
                </tr>
              <tr>
                <th><label for="universitario">Título Universitario</label></th>
                <td><input type="text" name="universitario" id="universitario" value="<?=v('universitario')?>" /></td>
                <th><label for="institucion2">Institución</label></th>
                <td><input type="text" name="institucion2" id="institucion2" value="<?=v('institucion2')?>" /></td>
              </tr>
              <tr>
                <th><label for="idiomas">Idiomas</label></th>
                <td><input type="text" name="idiomas" id="idiomas" value="<?=v('idiomas')?>" /></td>
                <th><label for="domIdioma">% de dominio</label></th>
                <td><input class="short" type="text" name="domIdioma" id="domIdioma" value="<?=v('domIdioma')?>" /> <a href="#" id="agregarId">[+] Agregar</a>
                          </tr>
                          <tr>
                <th><label for="sistemas">Manejo de sistemas</label></th>
                <td><input type="text" name="sistemas" id="sistemas" value="<?=v('sistemas')?>" /></td>
                <th><label for="domIdioma">% de dominio</label></th>
                <td><input class="short" type="text" name="domSistema" id="domSistema" value="<?=v('domSistema')?>" /> <a href="#" >[+] Agregar sistema</a></td>
              </tr>
              <tr>
                <th><label for="estudia">Estudia actualmente</label></th>
                <td><input class="short" name="estudia" type="radio" value="si" /><label for="si">Si</label> <input class="short" name="estudia" type="radio" value="no" /><label for="no">No</label></td>
                <th><label for="carrera">Carrera</label></th>
                <td><input type="text" name="carrera" id="carrera" value="<?=v('carrera')?>" /></td>
              </tr>
                        <script type="text/javascript" src="menu.js">
                                insertarIdioma();
                        </script>
            </table>
        </div>

el siguiente javascript:

Código:

function insertarIdioma()
{
        document.getElementById('agregarId').onclick = function() {

        row = document.createElement('tr');
        head1 = document.createElement('th');
        label1 = document.createElement('label');
       
        head2 = document.createElement('th');
        label2 = document.createElement('label');       
       
        text1 = document.createTextNode("Idiomas");
        data1 = document.createElement('td');
        input1 = document.createElement('input');
        input1.setAttribute("name","idiomas");
        input1.setAttribute("type","text");
       
        text2 = document.createTextNode("% de dominio");
        data2 = document.createElement('td');
        input2 = document.createElement('input');
        input2.setAttribute("name","domIdioma");       
        input2.setAttribute("type","text");
       
        label1.appendChild(text1);
        head1.appendChild(label1);
        row.appendChild(head1);
        row.appendChild(data1);
               
        data1.appendChild(input1);
       
        label2.appendChild(text2);
        head2.appendChild(label2);
        row.appendChild(head2);
               
        data2.appendChild(input2);
               
        row.appendChild(data2);

        document.getElementById('tabla').appendChild(row);
       
        return false;
        }
}

No me funciona, la verdad que no puedo localizar que problema tiene. Me ayudan?

marcopoloaz06 28/06/2008 10:26

Respuesta: consulta dom
 
hola,
solo tienes
que ponerlo
en la funcion onload
Código HTML:

onload = function(){

        document.getElementById('agregarId').onclick = function() {

        row = document.createElement('tr');
        head1 = document.createElement('th');
        label1 = document.createElement('label');
       
        head2 = document.createElement('th');
        label2 = document.createElement('label');       
       
        text1 = document.createTextNode("Idiomas");
        data1 = document.createElement('td');
        input1 = document.createElement('input');
        input1.setAttribute("name","idiomas");
        input1.setAttribute("type","text");
       
        text2 = document.createTextNode("% de dominio");
        data2 = document.createElement('td');
        input2 = document.createElement('input');
        input2.setAttribute("name","domIdioma");       
        input2.setAttribute("type","text");
       
        label1.appendChild(text1);
        head1.appendChild(label1);
        row.appendChild(head1);
        row.appendChild(data1);
               
        data1.appendChild(input1);
       
        label2.appendChild(text2);
        head2.appendChild(label2);
        row.appendChild(head2);
               
        data2.appendChild(input2);
               
        row.appendChild(data2);

        document.getElementById('tabla').appendChild(row);
       
        return false;
        }
}

saludos...
:]


La zona horaria es GMT -6. Ahora son las 04:26.

Desarrollado por vBulletin® Versión 3.8.7
Derechos de Autor ©2000 - 2026, Jelsoft Enterprises Ltd.