Ajax to show or hide divs in a form

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Ajax to show or hide divs in a form

 
0
  #1
Sep 16th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1,383
Reputation: almostbob has a spectacular aura about almostbob has a spectacular aura about almostbob has a spectacular aura about 
Solved Threads: 167
almostbob's Avatar
almostbob almostbob is offline Offline
Nearly a Posting Virtuoso

Re: Ajax to show or hide divs in a form

 
0
  #2
Sep 16th, 2009
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
  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.
Failure is not an option It's included free, you don't have to do anything to get it
If at first you dont succeed, join the club
Of course its always in the last place you look, you dont keep looking after you find it

Please mark solved problems, solved
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Re: Ajax to show or hide divs in a form

 
0
  #3
Sep 16th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 73
Reputation: filch is an unknown quantity at this point 
Solved Threads: 1
filch filch is offline Offline
Junior Poster in Training

Re: Ajax to show or hide divs in a form

 
0
  #4
Sep 17th, 2009
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC