Reply
Accessing Form Within AJAX Div
Old 04-14-2009, 07:40 PM Accessing Form Within AJAX Div
portkey's Avatar
Experienced Talker

Posts: 38
Name: Erica Dion
Trades: 0
I've got a comment posting script, written in PHP, that is loaded into an AJAX div. On that form are a bunch of smilies that when you click on one, it adds the special code into the textbox above, simple enough. Problem is, this only works when the page is NOT loaded into the AJAX div. It attempts to locate the form similar to the psuedo code below:

Code:
document.forms['formname'].mytextbox.value+=smilie
Of course, with AJAX, in the 'document' this form doesn't show up. The HTML code views it as an empty div even though something is filled in there. Could anyone tell me the proper way of reaching the textbox? I've tried all sorts of methods so far with no success.

Thank you!
portkey is offline
Reply With Quote
View Public Profile Visit portkey's homepage!
 
 
When You Register, These Ads Go Away!
Old 06-11-2009, 05:22 PM Re: Accessing Form Within AJAX Div
portkey's Avatar
Experienced Talker

Posts: 38
Name: Erica Dion
Trades: 0
So to write it more simply, does anyone have any ideas as how to access content in an AJAX div via Javascript, even though in the HTML source it appears blank?

I now have the code running in the main program so it recognizes it as a function, but now it tells me that the form field is undeclared. I know this is possible with regular frames because you can access similar to parent.frame_name.form1.....

Thank you!!
portkey is offline
Reply With Quote
View Public Profile Visit portkey's homepage!
 
Old 06-11-2009, 06:07 PM Re: Accessing Form Within AJAX Div
wayfarer07's Avatar
NYE-KEE

Posts: 3,136
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
It makes no difference whether code is viewable in the static HTML or not, as long as it is loaded in the DOM, it is accessible via normal methods. The problem is, you can't just plop a command just anywhere in your script, and expect it to read what you're loading via an AJAX call. You can only access that content once it has loaded, which means you must wait for the onreadystatechange event before you try to access it. If you read the DOM from that callback, and after you have inserted the content, you should have no problems.
__________________
Wayfarer | jQuery Tooltip Plugin
Freelance Jobs Available
If Google is the Coca-Cola of Web search, Bing is RC Cola
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 06-21-2009, 09:45 PM Re: Accessing Form Within AJAX Div
portkey's Avatar
Experienced Talker

Posts: 38
Name: Erica Dion
Trades: 0
thanks for the tip, it really helped point me in the right direction however it also gave me two more questions now. Firstly, the onreadystatechange event doesn't work in Firefox. Is there another way to implement it. Secondly, the form I'm trying to access is loaded into the AJAX frame via a hyperlink meaning that when the page loads, it's not present immediately so IE tells me that it's undeclared. Any ideas to help with that? I'm pretty new to AJAX so I appreciate all the help I can get!

Code:
document.onreadystatechange=function1;
var comment_location;
function function1 () {
	if (document.readyState=="complete") {
		comment_location = document.getElementById('blogdiv').comment_body
		alert("comment_location is "+comment_location);
	}
}
portkey is offline
Reply With Quote
View Public Profile Visit portkey's homepage!
 
Old 06-22-2009, 12:57 PM Re: Accessing Form Within AJAX Div
wayfarer07's Avatar
NYE-KEE

Posts: 3,136
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Quote:
Originally Posted by portkey View Post
Firstly, the onreadystatechange event doesn't work in Firefox.
Yes it does. The onreadystatechange event isn't a property of the document, it is an event property of a created xml http request object.

Here's a guide to help you make it work:
Creating an XML HTTP request Object
Using onreadystatechange to check for completed requests.
__________________
Wayfarer | jQuery Tooltip Plugin
Freelance Jobs Available
If Google is the Coca-Cola of Web search, Bing is RC Cola
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 07-04-2009, 03:45 PM Re: Accessing Form Within AJAX Div
portkey's Avatar
Experienced Talker

Posts: 38
Name: Erica Dion
Trades: 0
thanks for your help. I ended up just going into the AJAX code itself and entering my request variables directly after the page was loaded. Far easier
portkey is offline
Reply With Quote
View Public Profile Visit portkey's homepage!
 
Reply     « Reply to Accessing Form Within AJAX Div
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.13215 seconds with 13 queries