function cadProd(){
var nomeProd = document.getElementById("nomeProd").value;
var categoria = document.getElementById("categoria").value;
var descricao = document.getElementById("descricao").value;
var un = document.getElementById("un").value;
var qtd = document.getElementById("qtd").value;
var qtdMin = document.getElementById("qtdMin").value;
var table = document.getElementById("novosProds");
var row = table.insertRow(1);
row.insertCell(0).innerHTML = nomeProd;
row.insertCell(1).innerHTML = categoria;
row.insertCell(2).innerHTML = descricao;
row.insertCell(3).innerHTML = un;
row.insertCell(4).innerHTML = qtd;
row.insertCell(5).innerHTML = qtdMin;
row.insertCell(6).innerHTML = '<input type="submit" value="Deletar">';
return alert("Registro realizado com sucesso");
}
<!DOCTYPE pt-br>
<html>
<head>
</head>
<body>
<?php/*
include 'header.php';
*/?>
<div class='cadProd'>
<h1>Cadastrar Produto</h1>
<table border='2' id='cadastrar'>
<tr>
<th>Nome</th><th>Categoria</th><th>Descrição</th><th>Un. Medida</th><th>Qtd</th><th>Qtd Minima</th>
</tr>
<tr><form method='POST'>
<td>
<input type='text' name='nomeProd' id='nomeProd'/>
</td>
<td>
<select name='categoria' id='categoria'>
<option id='1'>Limpeza</option>
<option id='2'>Escritório</option>
<option id='3'>Uniforme</option>
<option id='4'>Acessórios</option>
</select>
</td>
<td>
<input type='descricao' name='descricao' id='descricao'>
</td>
<td>
<select name='un' id='un'>
<option id='1'>Un</option>
<option id='2'>Pct</option>
<option id='3'>Lts</option>
<option id='3'>Kilo</option>
</select>
</td>
<td>
<input type='number' name='qtd' id='qtd'>
</td>
<td>
<input type='number' name='qtdMin' id='qtdMin'>
</td>
<td>
<input type='submit' onclick='cadProd()' value='Cadastrar'/>
</td>
</form></tr>
</table>
<table border='2' id='novosProds'>
<tr>
<th>Nome</th><th>Categoria</th><th>Descrição</th><th>Un. Medida</th><th>Qtd</th><th>Qtd Minima</th>
</tr>
</table>
</div>
<body>
</html>
Well, if you look at the example, it's holding the line. My problem is that when this is executed here in my localhost, it deletes the line after inserting it.
This code is complete. If saving as html can see the problem:
<!DOCTYPE pt-br>
</head>
<body>
<div class='cadProd'>
<h1>Cadastrar Produto</h1>
<table border='2' id='cadastrar'>
<tr>
<th>Nome</th><th>Categoria</th><th>Descrição</th><th>Un. Medida</th><th>Qtd</th><th>Qtd Minima</th>
</tr>
<tr><form method='POST'>
<td>
<input type='text' name='nomeProd' id='nomeProd'/>
</td>
<td>
<select name='categoria' id='categoria'>
<option id='1'>Limpeza</option>
<option id='2'>Escritório</option>
<option id='3'>Uniforme</option>
<option id='4'>Acessórios</option>
</select>
</td>
<td>
<input type='descricao' name='descricao' id='descricao'>
</td>
<td>
<select name='un' id='un'>
<option id='1'>Un</option>
<option id='2'>Pct</option>
<option id='3'>Lts</option>
<option id='3'>Kilo</option>
</select>
</td>
<td>
<input type='number' name='qtd' id='qtd'>
</td>
<td>
<input type='number' name='qtdMin' id='qtdMin'>
</td>
<td>
<input type='submit' onclick='cadProd()' value='Cadastrar'/>
</td>
</form></tr>
</table>
<table border='2' id='novosProds'>
<tr>
<th>Nome</th><th>Categoria</th><th>Descrição</th><th>Un. Medida</th><th>Qtd</th><th>Qtd Minima</th>
</tr>
</table>
</div>
<script language='javascript'>
function cadProd(){
var nomeProd = document.getElementById("nomeProd").value;
var categoria = document.getElementById("categoria").value;
var descricao = document.getElementById("descricao").value;
var un = document.getElementById("un").value;
var qtd = document.getElementById("qtd").value;
var qtdMin = document.getElementById("qtdMin").value;
var table = document.getElementById("novosProds");
var row = table.insertRow(1);
row.insertCell(0).innerHTML = nomeProd;
row.insertCell(1).innerHTML = categoria;
row.insertCell(2).innerHTML = descricao;
row.insertCell(3).innerHTML = un;
row.insertCell(4).innerHTML = qtd;
row.insertCell(5).innerHTML = qtdMin;
row.insertCell(6).innerHTML = '<input type="submit" value="Deletar">';
return alert("Registro realizado com sucesso");
}
Any suggestions on this? Sincerely