...

View Full Version : jQuery function kills script



macleodjb
03-09-2011, 12:57 AM
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.



$(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();
}
});

venegal
03-09-2011, 07:02 AM
Lose the $(); around the function declaration. It doesn't make any sense and causes an error, which will halt script execution.

devnull69
03-09-2011, 08:28 AM
I guess venegal means the second function ... the first one (the anonymous one) is just fine

venegal
03-09-2011, 09:03 AM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum