Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    280
    Thanks
    25
    Thanked 9 Times in 9 Posts

    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

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    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?

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    280
    Thanks
    25
    Thanked 9 Times in 9 Posts
    i fixed this by using .bind but does anyone know how to bind the data that was retrieved from the previous functions?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •