AzeS Posted January 16, 2017 Share Posted January 16, 2017 im trying to open a modal div after the triggering event from a form, and it doesnt work, soon as i click the button it Flashes briefly anfd then... nothing php if (isset($_POST['btn_exe_det_prf'])) { $id = strip_tags($_POST['btn_exe_det_prf']); $id = trim($id); $reviews = $profile->coment_get($id); echo $id; echo "<script> $(window).Onload(Despair()); </script>"; } js <script> // Get the modal var modal = document.getElementById('myModal'); // Get the button that opens the modal var btn = document.getElementById("myBtn"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; // When the user clicks the button, open the modal function Despair() { modal.style.display = "block"; } // When the user clicks on <span> (x), close the modal span.onclick = function() { modal.style.display = "none"; } // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } </script> Quote Link to comment https://forums.phpfreaks.com/topic/302943-open-modal-after-php-wont-work/ Share on other sites More sharing options...
ginerjm Posted January 16, 2017 Share Posted January 16, 2017 How are these two code samples connected? PS - you might think about structuring your scripts to completely separate the html, the php and the js. Also you might build a proper web page rather than just echoing out some random js code in the middle of whatever is going on. Quote Link to comment https://forums.phpfreaks.com/topic/302943-open-modal-after-php-wont-work/#findComment-1541440 Share on other sites More sharing options...
Solution AzeS Posted January 16, 2017 Author Solution Share Posted January 16, 2017 Solved by my self, im sorry, i need to have more patience with my brain.... php if (isset($_POST['btn_exe_det_prf'])) { $id = strip_tags($_POST['btn_exe_det_prf']); $id = trim($id); $reviews = $profile->coment_get($id); echo $id; echo "<script> $(window).Onload(Despair()); </script>"; } Html <div id='myModal'>Some content</div> js <script> // Get the modal var modal = document.getElementById('myModal'); // Get the button that opens the modal var btn = document.getElementById("myBtn"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; // When the user clicks the button, open the modal function Despair() { modal.style.display = "block"; } // When the user clicks on <span> (x), close the modal span.onclick = function() { modal.style.display = "none"; } // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } </script> solution: php if (isset($_POST['btn_exe_det_prf'])) { $id = strip_tags($_POST['btn_exe_det_prf']); $id = trim($id); $reviews = $Shop->coment_get($id); echo $id; echo "<script> var trigger = 1; </script>"; } html <div id='myModal'>Some content<span>close</span></div> js <script> // Get the modal var modal = document.getElementById('myModal'); // Get the button that opens the modal var btn = document.getElementById("myBtn"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; // When the user clicks the button, open the modal function Despair() { modal.style.display = "block"; } // When the user clicks on <span> (x), close the modal span.onclick = function() { modal.style.display = "none"; } // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } </script> solution at the end of the script: <script> if (trigger == 1) { $(window).Onload(Despair()); trigger = 0; } </script> Quote Link to comment https://forums.phpfreaks.com/topic/302943-open-modal-after-php-wont-work/#findComment-1541442 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.