0
Hello, I have a modal that has a registration form, when I click to register it calls a code PHP, that registers the information and initiates a session
'done registration. After opening the session
it calls the page back, where is this modal. When starting this page HTML, some validations are executed. One of these validations is below.
What I want to do is click the button that opens this modal when this session
'done registration' for true
. For when the person registers an item, the page be reloaded and open the modal automatically.
I tried several codes, from several forums and none worked. If I put an Alert in this script works normally. But this code: document.getElementById("btnModalCategoria").click();
and others who tried the error of a comma point or no error, but it does not work.
<?php
if(isset($_SESSION['cadastro_efetuado'])):
echo "<script>
document.getElementById("btnModalCategoria").click();
</script">
endif;
unset($_SESSION['cadastro_efetuado']);
?>
I understood.. But in the case of onload, it would run every time the page was loaded again. I didn’t want to. I want it only when the registration SESSION is true.
– natanfoleto
I’ll explain it better. The event
onload
will be triggered when the entire HTML page and its features are rendered. If you put a script that handles a button even before the button is rendered, it will not work. Then the eventonload
waits for the resources to be loaded to then execute the scripts. And as your JS code is within the condition if the registration is equal totrue
, only in this case the script will be "embedded" in the code.– Victor Carnaval
Ahhhhh got it, it worked bro! Thanks really, I’ve been trying to fix it for days. Thanks!!
– natanfoleto
Give nothing @natanfoleto, I’m glad I helped you! If one of the responses from any user helped you get the expected result, mark it as the best response.
– Victor Carnaval