Browse Source

Creating validation javascript in the form

master
bianca-maria 3 years ago
parent
commit
4e22673359
2 changed files with 45 additions and 6 deletions
  1. +5
    -4
      index.html
  2. +40
    -2
      scripts/index.js

+ 5
- 4
index.html View File

@ -7,6 +7,7 @@
<link rel="stylesheet/less" type="text/css" href="styles/base.less"/>
<script src="scripts/less.min.js" type="text/javascript"></script>
<script src="scripts/index.js" defer></script>
</head>
@ -19,7 +20,7 @@
<main>
<h2 class="titulo">Requisitos de hardware</h2>
<table cellspacing="5" cellpadding="10" border="0">
<table cellspacing="5" cellpadding="10">
<thead>
<tr>
<th>Ano</th>
@ -45,12 +46,12 @@
</table>
<!-- action="salvar.html" -->
<form class="form" >
<form class="form" method="get">
<h2 class="form__titulo">Registre seu interesse</h2>
<div class="form__infor">
<label class="form__infor__label">Nome:</label>
<input type="text" name="nome" class="form__infor__input"/>
<input id="name" type="text" name="nome" class="form__infor__input"/>
</div>
<div class="form__infor">
<label class="form__infor__label" for="campo_sobrenome">
@ -83,6 +84,6 @@
<span>Todos os direitos reservados</span>
</footer>
<script src="scripts/index.js"></script>
</body>
</html>

+ 40
- 2
scripts/index.js View File

@ -1,6 +1,44 @@
let seleciona = document.getElementById("btn_enviar");
console.log(seleciona);
const nome = document.querySelector("#nome");
const sobrenome = document.querySelector("#campo_sobrenome");
const email = document.querySelector("#campo_email");
const checknews = document.querySelector("#check").checked;
const btnEnviar = document.querySelector("#btn_enviar");
let interesse = [];
function enviaDados() {
if (nome.value == "") {
alert('nome não preenchido')
nome.focus()
return
}
if (sobrenome.value == "") {
alert('sobrenome não preenchido')
sobrenome.focus()
return
}
if (email.value == "") {
alert('email não preenchido')
email.focus()
return
}
interesse.push(nome.value)
interesse.push(sobrenome.value)
interesse.push(email.value)
alert(interesse)
/*if(checknews.value != ''){
alert('email não preenchido')
email.focus()
return
}*/
}
btnEnviar.addEventListener("click", enviaDados)

Loading…
Cancel
Save