Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

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 06-08-2009, 06:35 AM   PM User | #1
snowysweb
Regular Coder

 
Join Date: Sep 2008
Posts: 280
Thanks: 25
Thanked 9 Times in 9 Posts
snowysweb is an unknown quantity at this point
jQuery - function not run

Hi all, here is my script i wrote (yet again, new to this, actually started this morning - 4am).

Code:
$(document).ready(function(){
		$("#test").change(onSelectChange);
	});
	function onSelectChange(){
	var dropDown1 = $("#test :selected").text()
		$.ajax({
			  type: "GET", data: "pg=<?php echo $_GET['pg']; ?>&word=" + dropDown1, url: "php/php_ajax_input_script.php", cache: false, success: 
			  function(html){
				$("#ajaxDiv").html(html); 
				$("#test2").change(onSelectChange2);
				}
				
			});
	}
	function onSelectChange2(){
	var dropDown2 = $("#test2 :selected").text()
		$.ajax({
			  type: "GET", data: "pg=<?php echo $_GET['pg']; ?>&word=" + dropDown2, url: "php/php_ajax_input_script2.php", cache: false, success: 
			  function(html){
				$("#ajaxDiv2").html(html); }
			});
	}
	
	//$("#updateContent").click( function() {
	//var word = $("#word").value()
	//alert('hghg')
		//$.ajax({
		//	  type: "GET", data: "pg=<?php echo $_GET['pg']; ?>&word=" + word + "&Name_value=" + nameValue, url: "php/php_ajax_input_script4.php", cache: false, success: function(html){
		//		$("#ajaxDiv4").html(html); }
		//	});
	//});
The last function will not run. The button with the id "updateContent" is loaded in by the previous function with AJAX call.

Any ideas why it wont work would be greatfull
snowysweb is offline   Reply With Quote
Old 06-08-2009, 03:01 PM   PM User | #2
Eldarrion
Regular Coder

 
Join Date: Feb 2009
Location: Wheeling, IL
Posts: 358
Thanks: 5
Thanked 62 Times in 60 Posts
Eldarrion is on a distinguished road
For starters, it looks to be commented out. I'm guessing though that's not the case in your test environment. But, if the button, called 'updateContent' comes in after load... you might want to stick the click assigning in the AJAX callback, rather than on load... because on load, the button does not exist and as such, the click event doesn't get assigned.

Other than that, I guess you can use .live rather than reassigning every time the AJAX completes. Look it up in jQuery's API.
__________________
The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

How to ask smart questions?
Eldarrion is offline   Reply With Quote
Old 06-08-2009, 03:10 PM   PM User | #3
snowysweb
Regular Coder

 
Join Date: Sep 2008
Posts: 280
Thanks: 25
Thanked 9 Times in 9 Posts
snowysweb is an unknown quantity at this point
i fixed this by using .bind but does anyone know how to bind the data that was retrieved from the previous functions?
snowysweb 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 12:47 PM.


Advertisement
Log in to turn off these ads.