1
When you click on one of the buttons on the page a modal with a form should open. But each button must contain a different form. I used the following code:
<script type="text/JavaScript">
// teste para ocultar menu
var ocultar = document.getElementById('header');
//Obter o modal
var modal = document.getElementById('myModal');
//Obter o botão que abre o modal
var btn = document.getElementById('myBtn');
//Obter o elemento <span> que fecha o modal
var span = document.getElementsByClassName("close")[0];
//Quando o usuário clicar no botão, abra o modal
btn.onclick = function() {
modal.style.display = 'block';
ocultar.style.display = ("none");
}
//Quando o usuário clicar em <span> (x), feche o modal
span.onclick = function() {
modal.style.display = 'none';
if(ocultar.style = "none"){
ocultar.style = ("block !important");
}
}
//Quando o usuário clica em qualquer lugar fora do modal, feche-o
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
ocultar.style = ("block !important");
}
}
But the modal is working only on the first button. On the other buttons it doesn’t happen anything. I already checked the console of Google Chrome, and it shows nothing of error.
If you want to take a look >>> WEBSITE WITH THE BUTTONS
if(ocultar.style = "none")
Was supposed to be==
– bfavaretto
It’s actually already working the way I put it. If I put == it stops working. The real problem is that it works on the first button of the page, and on others not!
– Gabriel Soligo
The way you put it, will always enter this if, and always change the style of the hide to None.
– bfavaretto
And it’s missing
.display
in various places you use only.style
.– bfavaretto
Sorry friend, I just tested your suggestions, but they had no effect. Did you get click on the link? maybe you understand what I mean.
– Gabriel Soligo