fanfavorite Posted June 26, 2008 Share Posted June 26, 2008 I create forms using PHP and use AJAX to add fields that are relevant and remove fields that aren't relevant as the user fills out the form. All works well with that. Now once the user hits submit, I reload the page to check for any missing information, etc. Again, all is fine to this point. However when there is missing information, I want the form to come up as it was just before the submit. This is where I have the problem. If I don't do anything, it will not show any of the updated AJAX information. Now I thought about that and thought that maybe if I do the javascript calls based on the POST variable values, I could make it how it was, but there are some errors. Heres the code: <form enctype="multipart/form-data" id="orderform" name="orderform" action="" method="post"> <div class="formsleft">Answer Yes/No</div> <div class="formsright"> <select name="yesnofield" onchange="showField(this.value,'havesite2')"> <option value="No"<? if ($_POST['website'] == "No") { echo ' selected="selected"'; } ?>>No</option> <option value="Yes"<? if ($_POST['website'] == "Yes") { echo ' selected="selected"'; } ?>>Yes</option> </select> <script type="text/javascript"> <!-- showField('<? echo $_POST[yesnofield]; ?>','havesite2'); showField('<? echo $_POST[transfertoats] ?>','transfertous') --> </script> </div> <div id="havesite2"></div> <div id="transfertous"></div> <input type="submit" alt="Submit" name="submit" id="submit" value=" " class="formsubmit" /> </form> Now the "yesnofield" populates the havesite2 and "transfertoats" is a yes/no field inside havesite2. This particular code in Firefox, will update fine if I put either showField call separately, but if they are together, the second one seems to override the first one depending on how fast the first one is. For example, sometimes when it loads it will show part of what is supposed to be in havesite2, with the transfertous script in both havesite2 and transfertous. Any help on this issue would be appreciated. Thanks, -JC Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 26, 2008 Share Posted June 26, 2008 i would use PHP to show/hide the needed information Quote Link to comment Share on other sites More sharing options...
fanfavorite Posted June 26, 2008 Author Share Posted June 26, 2008 I think you're right. Although it's duplicating code, will result in less errors. Quote Link to comment 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.