Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-17-2012, 07:26 PM   PM User | #1
Acheron
New to the CF scene

 
Join Date: Sep 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Acheron is an unknown quantity at this point
Manipulating ajax data after load

I currently have a script that it uses ajax to search, the results turn up and I have buttons to each result.

Code:
document.getElementById('buttonone').innerHTML = "Search Sent";
Works for the button that loaded with the original page
Code:
document.getElementById('buttontwo').innerHTML = "Added Ty";
Does not work for the button loaded with ajax

Is there a way to register the new elements on ajax load?
Acheron is offline   Reply With Quote
Old 09-17-2012, 08:09 PM   PM User | #2
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,696
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
You need to put that into the callback of the AJAX function.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 09-17-2012, 08:47 PM   PM User | #3
Acheron
New to the CF scene

 
Join Date: Sep 2012
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Acheron is an unknown quantity at this point
Nm I found it, I had to reinitialize the whole thing after the first return of the ajax so the doc would find it.

Last edited by Acheron; 09-17-2012 at 09:01 PM..
Acheron is offline   Reply With Quote
Old 09-17-2012, 09:13 PM   PM User | #4
phenem
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 1 Time in 1 Post
phenem is an unknown quantity at this point
Hi Acheron,

Are you open to using jQuery, it would make things a bit simpler.

I'll try to show you what VIPStephan means using a jQuery example:

Code:
<h1>Search</h1>

<div id="searchResults">

</div>

<script type="text/javascript">
$(function(){
	
	function getSearchResults(){
		$.post(
			'url-to-my-search.html',
			{'searchQuery':'search-string'},
			function(html){
				//we're now inside the callback				
				//perform actions with data returned from search form
				$('#searchResults').html(html);
				
				//this is where you can put your event for your button
				$('#button').bind('click', function(e){
					getSearchResults();
				});
			});
	}
	
	getSearchResults();
	
});
</script>
Your button will have to be on the page: "url-to-my-search.html"

I just ran into this issue myself the other day, and this is how I resolved it.
phenem is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 04:40 AM.


Advertisement
Log in to turn off these ads.