1
Person, all right? So, I have an alert div (that of bootstrap) with the None display and Hidden visibility I’m getting it by id, both in css and javascript, only it doesn’t work. It changes the properties of CSS but still sends the data to PHP, the validation is not worth anything haha. Help me, please. this is one of the inputs I want to validate.
<input type="text" name="pergunta" data-placement="bottom" class="form-control" placeholder="Ex: XXXXXXXXXX?" aria-describedby="basic-addon1">
This is the div I put as Hidden by default, it is positioned below the input:
<div class="alert alert-danger" id="valida_pergunta" role="alert"><span class="glyphicon glyphicon-info-sign"></span> Preencha o campo Pergunta</div>
When I click, I want it to display the div that is like Hidden and do not send anything to PHP.
function validar (){
var pergunta = form_pergunta.pergunta.value;
var resposta = form_pergunta.resposta.value;
var desafio = form_pergunta.desafio.value;
if(pergunta==""){
document.getElementById("valida_pergunta").style.display = "flex";
}
if (resposta == "") {
document.getElementById("valida_resposta").style.display ="flex";
}
if (desafio ==""){
document.getElementById("valida_desafio").style.display = "flex";
}
}
I’m using an input of type Submit, and the elements are inside a form, this has problem?
– Tiago Silveira
No problem. makes a
console.log(input)
to know if you are recovering the inputs correctly.– Andrew Ribeiro
I still don’t know how to use this function, maaaaas, I gave an if on the variable you receive, if you have empty it gives an Alert, if not, it does nothing. worked, is getting the data.
– Tiago Silveira
console.log()
is a function to log everything that is javascript object. To see the log just press F12 (Chrome) and go in the Console tab. Anyway, with Alert also works. Remove the CSS that is changing the visibility of the div and only move with the display, as I showed in the code. Inclusive, you can copy the code if you want, feel free.– Andrew Ribeiro
solved the problem, now it validates all fields, I took the php action from the form, it validates and returns the original page, only it does it very fast. If I put php action it validates but sends anyway.
– Tiago Silveira
function validar (){
 var pergunta = form_pergunta.pergunta.value;
 var resposta = form_pergunta.resposta.value;
 var desafio = form_pergunta.desafio.value;
 if(pergunta==""){
 document.getElementById("valida_pergunta").style.display = "flex"; } if (answer == "") { Document.getElementById("valida_response").style.display ="flex"; } if (challenge ==""){ Document.getElementById("valida_challenge").style.display = "flex"; } }
– Tiago Silveira
Now it’s validated, fine, just that I want it to stop and don’t send anything to php kkkk he’s sending anyway.
– Tiago Silveira
Edit your question and put the whole javascript code so I can help you.
– Andrew Ribeiro
Let’s go continue this discussion in chat.
– Tiago Silveira