Jump to content

Why won't this code run when button is pressed?


Darkmatter5

Recommended Posts

<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?

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.