var CustomerBoxesLoad = function () {
var handleAjaxBoxesSelectedCountry = function() {
$.ajax({
type: "POST",
url: 'ajax/selectbox/country_selected.php',
dataType:'json',
success: function(data) {
var select = $("#countryCodeBox"), options = '';
select.empty();
options += "<option value='0'>Select ...</option>";
for(var i=0;i<data.length; i++)
{
options += "<option value='"+data[i].id+"'>"+ data[i].name +"</option>";
}
select.append(options);
}
});
}
var handleAjaxBoxesCustomerType = function() {
$.ajax({
type: "POST",
url: 'ajax/selectbox/customer_type.php',
dataType:'json',
success: function(data) {
var select = $("#customerTypeBox"), options = '';
select.empty();
options += "<option value='0'>Select ...</option>";
for(var i=0;i<data.length; i++)
{
options += "<option value='"+data[i].id+"'>"+ data[i].name +"</option>";
}
select.append(options);
}
});
}
return {
//main function to initiate the module
init: function () {
handleAjaxBoxesSelectedCountry();
handleAjaxBoxesCustomerType();
}
};
}();
I have a function calling from a PHP file. At the end of the PHP file i am calling the Ajax function:
jQuery(document).ready(function() {
CustomerBoxesLoad.init();
});
All the Ajax select boxes filling works good. Now i want to trigger the Ajax script from a (a href="") tag. But the function will not trigger like this:
a href="javascript:handleAjaxBoxesSelectedCountry();">Refresh Select Box
THIS reference to the JavaScript dont work!!
add another function to your return:
return {
//main function to initiate the module
init: function () {
handleAjaxBoxesSelectedCountry();
handleAjaxBoxesCustomerType();
}
handleAjaxBoxesSelectedCountry: function () {
handleAjaxBoxesSelectedCountry();
}
};
and the 'a' tag:
<a href="javascript:CustomerBoxesLoad().init();return false;">STH</a>
I solved it myself:
return {
//main function to initiate the module
init: function () {
handleAjaxBoxesCountry();
handleAjaxBoxesCustomerType();
},
init_country: function () {
handleAjaxBoxesCountry();
},
init_type: function () {
handleAjaxBoxesCustomerType();
}
};