I am building a large registration form. In this form, a sponsor/educator must register himself or herself and then may add up to 6 more " delegates" in pairs. The first two pairs registration info on the form is shown by default. I need to hide the other two pairs until when/if the user clicks on a button to add two more delegates at a time. I used javascript to show or hide the parts of the form that I had put into two divs and adjusted the css display attribute. However, my problem was that, if the user filled out the sponsor/educator section and the first two delegates, and then decided to add two more, when the user clicked on the button to show the part of the form for delegates 3 and 4, it reset all the previous visible form fields to empty. Not good. So, I thought, maybe AJAX.

I created the request object (I am a relative novice at AJAX), had it grab a text file with the code to insert into my target div, in this case a div with id = "delegate3and4". Surprisingly however, it still reset the previous form fields to empty. Am I misunderstanding how AJAX is supposed to work? I figured that, because it does not refresh the page that this would not happen. In fact, to test this out, I created a simple page from scratch with just a single input field and then used AJAX to insert the file in a div after this field and it did not reset the previous input. So, I am totally confused about why this would be happening on my live page. The page is a php page as it submits the form to a php script for processing but I don't think this should make a difference.

Sorry for the long assed description but any help here would be very much appreciated as I have to get this finished today somehow.



Ajax , I dont know how it works at all, reading this forum to get info on things that work and dont work before I try any ajax
in php I do something like

<input type='text' id='something' value='<?php if(isset($_POST['something'])) {echo $_POST['something']; } ?>'>

to preserve the fields values,
is there something simliar in AJAX

Yeah ... I have something like that already. I am using:

<input name="address1edu" type="text" class="contactform" id="address1edu" value="<?PHP echo $_REQUEST ?>" size="30" />

This does not work. So yours looks like it might. I will give it a go.


However ... it still confuses me why I would have to do this at all. Using AJAX is supposed to mean the form has not been posted yet when I make the AJAX call so the fields should not be affected. Am I off base here?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.