Jump to content

[SOLVED] Reinsert Ajax Data After Form Submit


fanfavorite

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.