943,640 Members | Top Members by Rank

Ad:
Sep 16th, 2009
0

Ajax to show or hide divs in a form

Expand Post »
Ho,

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.

Cheers

Dave
Similar Threads
Reputation Points: 10
Solved Threads: 1
Junior Poster
filch is offline Offline
132 posts
since Nov 2008
Sep 16th, 2009
0

Re: Ajax to show or hide divs in a form

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
php Syntax (Toggle Plain Text)
  1. <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
Last edited by almostbob; Sep 16th, 2009 at 5:24 pm.
Reputation Points: 562
Solved Threads: 368
Posting Maven
almostbob is offline Offline
2,970 posts
since Jan 2009
Sep 16th, 2009
0

Re: Ajax to show or hide divs in a form

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

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

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

Dave
Reputation Points: 10
Solved Threads: 1
Junior Poster
filch is offline Offline
132 posts
since Nov 2008
Sep 17th, 2009
0

Re: Ajax to show or hide divs in a form

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?
Reputation Points: 10
Solved Threads: 1
Junior Poster
filch is offline Offline
132 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: I was wondering what the advantages to JQuery?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Sorting and Displaying names





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC