Forum Moderators: open

Message Too Old, No Replies

Problem with Ajax

         

yveslebeau

2:53 pm on Jun 22, 2007 (gmt 0)

10+ Year Member



Hi,

I have a problem with Ajax, PHP and mysql. I have a php page that has a form and the user can select with many checkboxes the options he desires. Then he clicks a button to fetch the different options in the database (going through Ajax). Now each options coming back from Ajax (after fetching the values in MySQL) have checkboxes. I tried to get access to the checkboxes returned by Ajax and it keep returning me 'null'. I gave them all dynamic ID in the id part and used the getElementById function but nothing works. Can you please help me?

Thank you

ahmedtheking

6:28 pm on Jun 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well there aren't many details here. Can you dump your code?

[edited by: DrDoc at 6:52 pm (utc) on June 22, 2007]
[edit reason] Removed URL. [/edit]

DrDoc

6:55 pm on Jun 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



First of all, welcome to WebmasterWorld! [WebmasterWorld.com]

Second, don't dump your code. ;) Please review the posting guidelines [WebmasterWorld.com] and JS/AJAX Forum Charter [WebmasterWorld.com] before posting code.

The key here is -- relevant code.

Now each options coming back from Ajax (after fetching the values in MySQL) have checkboxes. I tried to get access to the checkboxes returned by Ajax and it keep returning me 'null'.

What do they look like when they come back, and how are you inserting these newly returned checkboxes on the page? Subsequently, how are you trying access these checkboxes?

If posting any code -- only post code relevant to those two questions first, as they are key to understanding your problem and the resolution thereof.

StupidScript

10:14 pm on Jun 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Without waiting for the relevant code ;), it sounds like you are trying to access the "sub-page" provided by your AJAX request from the "parent page" that contains it. If so, the "sub-page" (AJAX response) DOM elements are probably not being initialized in the "parent page" DOM.

When the AJAX response is returned, you need to tell the "parent page" ... "We're baaaack!" by walking the response's DOM and handing its element identifiers back "up" to the script running in the "parent page".

Because this is wicked hard to explain without an example, I'll use an iframe example:

1) "Parent page" contains an iframe with "sub-page" loaded into it.
2) A link loads a new "sub-page" into the iframe.

How can the "parent page" get DOM information about the new page without being told? Well, the new page can reinitialize the script variables in use by the "parent page" as the new page loads, and then the "parent page" will know what to do.