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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    317
    Thanks
    24
    Thanked 3 Times in 3 Posts

    jQuery function kills script

    Hi guys,

    I'm pretty new to jquery and I am trying to run a function every time my select box is changed. My code is below. What is happening is that whenever i have the function call in the text it kills the rest of my script. if i comment it out everything else works fine. Not sure what is wrong. I would like the run toggle_games_div() every time my select box is changed.

    Code:
    $(function(){
    	$('#country').change(function(){
    	$(toggle_games_div());
    	var Selected = document.getElementById('country').value
    		if(Selected > 0){
    		
    			var data = {
    			action: 'get_country_games',
    			cat_id: $('#country').val()
    			};
    	
    			jQuery.post(LPAjax.ajaxurl + "/mygames.php", data, function(response) {
    				alert('Got this from the server: ' + response);
    			});
    		};//EndIF
    	});//End of Change function						  
    });
    
    $(function toggle_games_div(){
    	var CValue = document.getElementById('country').value;
    	if(CValue > 0){
    		$('#table_wrapper_toggle').show();
    	} else {
    		$('#table_wrapper_toggle').hide();
    	}
    });

  • #2
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Lose the $(); around the function declaration. It doesn't make any sense and causes an error, which will halt script execution.

  • #3
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,398
    Thanks
    12
    Thanked 570 Times in 563 Posts
    I guess venegal means the second function ... the first one (the anonymous one) is just fine

  • #4
    Gütkodierer
    Join Date
    Apr 2009
    Posts
    2,127
    Thanks
    1
    Thanked 426 Times in 424 Posts
    Quote Originally Posted by devnull69 View Post
    I guess venegal means the second function ... the first one (the anonymous one) is just fine
    That's right. I wouldn't call the anonymous function a function declaration, though, as that would at least imply a function name. But there's certainly no harm in specifying what I meant.

  • Users who have thanked venegal for this post:

    macleodjb (03-09-2011)


  •  

    Posting Permissions

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