Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

weslley clyton

Tabela Dinâmica com JavaScript

Recommended Posts

Ola Pessoal..

 

Seguinte, eu tenho aq uma tabela dinâmica funcionando perfeitamente, mas meu problema é o seguinte, quando eu vou dar o submit no form e mandar os dados pro php para serem gravados do BD eu não sei como pegar os dados dos inputs, pois não sei o nome dos mesmos.

 

 

Aqui a função juntamente com a tabela:

 


    <script>

		var d = document ;
        window.onload = function(){
                
				d.getElementById( 'firstLink' ).onclick = function(){ removerTr( 1 ) }
        
                d.getElementById( 'add' ).onclick = function(){
                        var oTable = d.getElementById( 'tabela' ) ;
                        var newTr  = oTable.insertRow( -1 ) ;
                        
                        newTr.setAttribute( 'id' , 'row' + oTable.rows.length ) ;
                        newTr.insertCell(0).appendChild( getLinkExcluir( oTable.rows.length ) ) ;
                        newTr.insertCell(1).appendChild( getInput() ) ;
						newTr.insertCell(2).appendChild( getInput() ) ;
						newTr.insertCell(3).appendChild( getInput() ) ;
						newTr.insertCell(4).appendChild( getInput() ) ;
                }
        }
        
        function getLinkExcluir( rowId )
        {
                var oA = d.createElement( 'a' ) ;
                oA.setAttribute( 'href' , '#' ) ;
                oA.innerHTML =  'excluir' ;
                oA.onclick = function(){ removerTr( rowId ) ; }
                return oA ;
        }
        
        function getInput()
        {
                var oInput = d.createElement( 'input' ) ;
                oInput.setAttribute( 'name' , 'inputs[]' ) ;
				return oInput ;
        }
        
        function removerTr( rowId )
        {
                var iRow = d.getElementById( 'row' + rowId ).rowIndex ;
                d.getElementById( 'tabela' ).deleteRow( iRow ) ;
                return false ;
        }


</script>

 

e Aqui o Html:

 


   <form>                
	<table id='tabela'>
       <tr id='row1'>                        
       	<td><a id='firstLink' href='#'>excluir</a></td>
        <td>
        	<input type="text" name='inputs[]'>                         
       </td>                  
      </tr>                
    </table>                
    <div><input type="submit"></div>        
</form>        
<button id='add' type='button'>Adicionar</button>

 

como veêm ele usa um array para guardar o nome de cada linha adicionada, mas eu não estou conseguindo visualizar este nome, quando eu der o submit como é q eu vo pegar la no php os nomes dos inputs por exemplo: $nome = $_POST['??????'];

Compartilhar este post


Link para o post
Compartilhar em outros sites

<?php

if(isset($_POST["input"])) {

echo "Os campos que você adicionou são:<br><br>";

 

// Faz loop pelo array dos campos:

foreach($_POST["input"] as $campo) {

echo $campo."<br>";

}

}else{

echo "Você não adicionou dados em nenhum campo!";

}

?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.