0
var clientes = [];
function classClientes(nro, nome, sexo,dataNasc) {
this.nro = nro;
this.nome = nome;
this.sexo = sexo;
this.dataNasc = dataNasc;
}
function criarCliente() {
var numeroCliente = document.getElementById("txtNumero").value;
var nomeCliente= document.getElementById("txtNome").value;
var sexoCliente = document.getElementById("txtNome").value;
var dataNascCliente = document.getElementById("dataNasc").value;
var repete = 0;
if (!isNaN(numeroCliente) && !isNaN(nomeCliente) && !isNaN(sexoCliente)) {
for (var j = 0; j < clientes.length; j++) {
if (clientes[j].nro == numeroCliente) {
clientes[j].nome = nomeCliente;
clientes[j].sexo = sexoCliente;
repetido = 1;
}
if (repetido == 0) {
var novoCliente = new classClientes(numeroCliente, nomeCliente, sexoCliente, dataNascCliente);
clientes.push(novoCliente);
}
}
}
}
I need to enter a new client when the user fills in the form (code below) as I do this using a javascript function and calling the function in an HTML5 button inside the form that the form is?
Form code with form (HTML5):
<!DOCTYPE html>
<html lang="pt-pt">
<head>
<title></title>
<meta charset="utf-8"/>
<script type="text/javascript" src="javascript.js"></script>
<link rel="stylesheet" type="text/css" href="estilos.css" />
</head>
<body>
<div id="novoCliente">
<form action="#">
<label for="lbNumero">Número:</label>
<input type="text" id="txtNumero" style="width:250px" /><br />
<label for="lbNome">Nome:</label>
<input type="text" id="txtNome" style="width:250px" /><br />
<label for="lbSexo">Sexo:</label>
<input type="radio" name="sexo" value="masculino">Masculino
<input type="radio" name="sexo" value="feminino">Feminino <br />
<label for="lbDataNasc">Data Nascimento:</label>
<input type="date" id="dataNasc" /><br />
<input type="button" id="criarCliente" class="botaoOperacao" value="Criar" onclick="javascript: criarCliente();" />
<input type="reset" id="cancelar" class="botaoOperacao" value="Cancelar"/>
</form>
</div>
</body>
</html>
Can you explain better where you want to "insert a new client"? Create another div in HTML
<div id="novoDoente">
? within the existing form? in a database? Explain better what you want to do to help better...– Sergio
I am not saving in a database...the information will be lost with each re-load of the html page, it was even to be able to work better with javascript since I have some difficulty
– Mario Medeiros
I place here my attempt
– Mario Medeiros