2
Good Morning, I am creating a form in html and javascript for validation, my idea is to create a success or failure alert with html and css (cute and etc), but I do not know how to "call" give a require in this alert I created, can anyone help me? Thank you!
<!DOCTYPE html>
<html>
<body>
<form id="form1" action="">
Nome: <input type="text" name="name" value="Nome"><br>
Sobrenome: <input type="text" name="sname" value="Sobrenome"><br><br>
</form>
<button onclick="takeValue()">mostra valor</button>
<p id="teste"></p>
<script>
function takeValue() {
var x = document.getElementById("form1");
var texto = "";
var i;
for (i = 0; i < x.length ;i++) {
texto += x.elements[i].value + "<br>";
}
document.getElementById("teste").innerHTML = texto;
if(texto == "Nome<br>Sobrenome<br>"){
alert("quero exibir alerta de SUCESSO feito com html e css");
}
else{
alert("quero exibir alerta de ERRO feito com html e csss");
}
}
</script>
You can use jQuery?
– Felipe Avelar
you have an example of code so I can understand the idea?
– Thiago Freitas
jQuery is a javascript library that already has a lot of stuff ready. In this case, to make a modal/dialog, as you wish, just use jQuery-UI and customize the box as you wish... That’s why I asked if you can use jQuery.
– Felipe Avelar
Explain how you want to display this message. If it is by a text on the page, by a modal dialog, an Alert, etc.
– Randrade
I wanted my alert of this 'display' in the div where the form is being filled, to warn if something is missing etc.. those very generic that we see in most Formulars
– Thiago Freitas
Ah, you can create two Divs, one for the error message and one for the success message.. hence both leaves with "display:None". Then just use a style.display = 'block' in the desired div.
– Ricardo