Darkmatter5 Posted January 20, 2009 Share Posted January 20, 2009 <script language="javascript"> function toggle() { var ele=document.getElementById("toggleDiv"); var text=document.getElementById("displayText"); if(ele.style.display=="block") { ele.style.display="none"; } else { ele.style.display="block"; } } </script> <div id="toggleDiv" style="display: block"> <span class="medium_text">Notes: <ol> <li>All fields marked with a red asterisks denotes a required field.</li> <li>Game cover scans you supply are not always used in the final database record.<br> If we deem the image of poor quality, etc... we will most likely delete the image<br> and aquire one on our own.</li> </ol> </span> <form method="post"> <label for="title"><b>Title<span class="required_text"> *</span></b></label><br> <input type="text" size="100" maxlength="100" name="title"><p> <label for="desc"><b>Description</b></label><br> <textarea cols="50" rows="10" name="desc"></textarea><p> <label for="genre"><b>Genre<span class="required_text"> *</span></b></label><br> <?php $vein->list_genres(3,''); ?><p> <fieldset style='width: 500px;'> <legend>System(s)</legend> <table><tr><?php $vein->const_fieldset(systems); ?></tr></table> </fieldset><p> <fieldset style='width: 500px;'> <legend>Publisher(s)</legend> <table><tr><?php $vein->const_fieldset(publishers); ?></tr></table> </fieldset><p> <fieldset style='width: 500px;'> <legend>Developer(s)</legend> <table><tr><?php $vein->const_fieldset(developers); ?></tr></table> </fieldset><p> <input name="submit" type="button" value="Submit game" onclick="toggle();"> </form> </div> <?php if(isset($_POST['submit'])) { echo "<input type='button' value='Add another game' onclick='toggle();'>"; } ?> If I comment out the "If part of the code and the closing bracket the button shows, but I want the button to appear only after the submit button is pressed. Why isn't it working? Link to comment https://forums.phpfreaks.com/topic/141603-why-wont-this-code-run-when-button-is-pressed/ Share on other sites More sharing options...
shedokan Posted January 20, 2009 Share Posted January 20, 2009 maybe you forgot the action property of the form? Link to comment https://forums.phpfreaks.com/topic/141603-why-wont-this-code-run-when-button-is-pressed/#findComment-741179 Share on other sites More sharing options...
haku Posted January 20, 2009 Share Posted January 20, 2009 Gotta tell us what button you are speaking of mate. Link to comment https://forums.phpfreaks.com/topic/141603-why-wont-this-code-run-when-button-is-pressed/#findComment-741256 Share on other sites More sharing options...
Darkmatter5 Posted January 20, 2009 Author Share Posted January 20, 2009 The javascript toggles the DIV on and off as the button named "submit" is pressed. The PHP code at the bottom of the page is suppose to also run as the "submit" button is pressed. I've tried disabling the javascript so the div won't hide and placing the PHP code inside the <form></form> tags, but still nothing. Link to comment https://forums.phpfreaks.com/topic/141603-why-wont-this-code-run-when-button-is-pressed/#findComment-741268 Share on other sites More sharing options...
cooldude832 Posted January 20, 2009 Share Posted January 20, 2009 PHP can't run after a page loads a new instant of the request needs to be made via AJAX or a page request via a normal page load Link to comment https://forums.phpfreaks.com/topic/141603-why-wont-this-code-run-when-button-is-pressed/#findComment-741273 Share on other sites More sharing options...
shedokan Posted January 21, 2009 Share Posted January 21, 2009 ajax is a dynamic browser language so you can change the html without page reload, but php is based on server and can only run if you reload a page. so pick the one that suits you, in your problem you can use ajax to post to the server and if successful so display the button using hidden div's. Link to comment https://forums.phpfreaks.com/topic/141603-why-wont-this-code-run-when-button-is-pressed/#findComment-741980 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.