-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFRONT-END 15_08_2023
79 lines (54 loc) · 1.8 KB
/
FRONT-END 15_08_2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<html>
<head>
<title>Gerente de Produtos</title>
<style></style>
<link rel="stylesheet" href="estilo css">
</head>
<body>
<div class="container">
<h1>Gerente de Produtos e Listagem</h1>
<form id="formProduto">
<label>Identificador</label>
<input type="number" id="Identificador" required>
<label>Nome do produto:</label>
<input type="text" id="produtoNome" required>
<label>Preço do Produto:</label>
<input type="number" id="produtoPreco"
required step="0.01">
<button type="submit">Cadastrar</button>
</form>
<hr>
<h2>Lista de produtos</h2>
<input type="text" id="buscar" placeholder="Buscar nome">
<ul id="produtoLista"></ul>
</div>
<script></script>
<script src="programa.js"></script>
</body>
</html>
JAVA SCRIPT
const formProdutop =
document.getElementById("formProduto");
const produtoLista =
document.getElementById("produtosLista");
formProduto.addEventLisstener('submit', adicionar);
const produtos = []; // vetor
function adicionar(){
var produtoNome =
document.getElementById("produtoNome").value;
var produtoPreco =
document.getElementById("produtoPreco").value;
//casaV é um elemento do meu vetor
var casaV = {nome: proudutoNome, preco: produtoPreco};
produtos.push(casaV);
imprimirLista(); //funcao de imprimir no html
}
function imprimirLista(){
produtoLista,innerHTML = ;
for(let i = 0; i < produtos.length; i++){
var elem = produtos[i];
var li = document.createElement('li');
li,innerHTML = `${elem.nome} - R$ ${elem.preco}`;
produtoLista.appendChild(li);
}
}