Ver Mensaje Individual
  #11 (permalink)  
Antiguo 02/08/2005, 03:20
Avatar de markshock
markshock
 
Fecha de Ingreso: abril-2004
Ubicación: Allí, al fondo a la izqui
Mensajes: 316
Antigüedad: 20 años
Puntos: 0
tema solucionado, ya tengo el aplicativo...

para quien quiera mirarselo... (seguramente se pueda simplificar pero es mi primer script con DOM)

Este code lo he hecho para agregar partidos a 1 campeonato.

Código:
<html>
<head>

<script language="JavaScript">
<!--//
var newsInputs = 0;
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++;

	newNode.appendChild(document.createElement('td'));       // creamos un td dentro de newNode
	newNode.lastChild.appendChild(document.createTextNode('Game '+(total+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 y = 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="0" width="380" cellspacing="2" cellpadding="0">
<tbody id="tableMatchs">
  <tr>
		<td width="40">Game 1</td>
		<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>Game 2</td>
		<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><img src="clear_pixel.gif" width="1" height="1" border="0"></td>
		<td><img src="clear_pixel.gif" width="1" height="1" border="0"></td>
		<td><img src="clear_pixel.gif" width="1" height="1" border="0"></td>
		<td><img src="clear_pixel.gif" width="1" height="1" border="0"></td>
	</tr>
</tbody>
</table>
<br>
<table border="0" width="380" cellspacing="0" cellpadding="0">
    <tr><td><center id="controlMatch"><a href="javascript:addMatch();">Añadir partido</a>&nbsp;&nbsp;&nbsp;&nbsp;</center></td></tr>
</table>
</form>
</body>
</html>
Soy juan palomo, yo me lo guiso yo me lo como xD xD xD
__________________
Señoooraaaa!! Que camisetas!!!

"Hay 10 tipos de personas, las que piensan en binario y las que no"
_________________________________