Ver Mensaje Individual
  #3 (permalink)  
Antiguo 08/02/2005, 03:01
Avatar de JavierB
JavierB
Colaborador
 
Fecha de Ingreso: febrero-2002
Ubicación: Madrid
Mensajes: 25.052
Antigüedad: 22 años, 3 meses
Puntos: 772
Hola markshock

Creo que esto servirá:
Código PHP:
<html>
<
HEAD>
<
SCRIPT LANGUAGE="JavaScript">
<!--
//
var newsInputs 0;
var 
defecto 4;
function 
addMatch(){
    var 
puntero document.getElementById('tableMatchs'); //recogemos donde van a ir los nuevos campos
    
newNode document.createElement('tr'); //creamos un elemento TR para poder agregar TD's
    
total 2//definimos cuantos inputs queremos insertar de un tiron
    
newsInputs++;
    for(
i=0;i<total;i++){
        var 
num_equipo document.getElementsByName('equipo').length//recogemos el total de campos equipo que hay para asignar los nuevos ID's
        
newNode.appendChild(document.createElement('td'));     // creamos un td dentro de newNode
        
        
var newField document.createElement('input'); //creamos un elemento input
        
newField.name 'equipo'//le asignamos un nombre al input creado
        
        
var newEquipo num_equipo 1// incrementamos el total de campos equipos para poder obtener un ID correlativo.

        
newField.id 'equipo'+newEquipo//asignamos el nuevo ID al nuevo INPUT
        
newNode.lastChild.appendChild(newField); //le indicamos de quien va a ser hijo.
        
if(i<1){                                //si es la primera vez insertamos un TD como separador
            
newNode.appendChild(document.createElement('td'));    
            
newNode.lastChild.appendChild(document.createTextNode('vs'));
        }
    
inicio=document.getElementById('nextMatch');
        
puntero.insertBefore(newNode,inicio);    //insertamos todos justo encima del tr con id nextMatch, almacenado en puntero.
    
}

    if(
newsInputs==1){//añadimos el link de borrar último partido
        
newClose document.createElement('a');
        
newClose.id='delPartido';
        
newClose.href='javascript:delMatch()';
        
newClose.appendChild(document.createTextNode('Borrar último'));
        
document.getElementById('controlMatch').appendChild(newClose);
    }
    
centrarContenido();//centramos el contenido de los TD's para que queden bien alineados

}

function 
centrarContenido(){
    var 
document.getElementById('tableMatchs').rows;
    for(
a=0;a<y.length;a++){
        
y[a].align='center';
    }
}

function 
delMatch(){
    var 
total document.getElementById('tableMatchs').getElementsByTagName("tr").length-2;
    
separador document.getElementById("tableMatchs");
    
separador.removeChild(separador.getElementsByTagName('tr')[total]);
    
newsInputs --;
    if (
newsInputs==0){
        
//retirar el código para borrar la última dirección de mail 
        
document.getElementById("controlMatch").removeChild(document.getElementById("delPartido"));
    }
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<form method="POST">
<table border="1" width="380" cellspacing="2" cellpadding="1">
<tbody id="tableMatchs">
    <tr><td align="center"><INPUT TYPE="text" NAME="equipo" id="equipo1"></td><td width="10" align="center">vs</td><td align="center"><INPUT TYPE="text" NAME="equipo" id="equipo2"></td></tr>
    <tr><td align="center"><INPUT TYPE="text" NAME="equipo" id="equipo3"></td><td align="center">vs</td><td align="center"><INPUT TYPE="text" NAME="equipo" id="equipo4"></td></tr>
    <tr id="nextMatch"><td>-</td><td>-</td><td>-</td></tr>
</tbody>
</table>
<br>
<table border="1" width="380">
    <tr><td><center id="controlMatch"><a href="javascript:addMatch();">Añadir partido</a>&nbsp;&nbsp;&nbsp;&nbsp;</center></td></tr>
</table>
</form>
</body>
</html> 
Saludos,