I'm facing an issue with my ajax call where the returned HTML works well on changes, but the Javascript that should perform actions based on clicks within the results is not functioning properly.
Here is the ajax call:
function update_order_shipping(){
$.ajax({
url: 'ajax_order_shipping.php',
method: "post",
dataType: 'html',
success: function (result) {
$('#shipping-method').html(result);
},
error: function(xhr, status, error) {
//alert(xhr.responseText);
}
});
};
The ajax call itself works perfectly and returns the required results.
The problem arises with the radio buttons in the returned results. When I try to execute the following JavaScript upon a change event:
$('input[name="shipping"]').change(function() {
if($(this).is(':checked') && ($(this).val() == 'freeamount_freeamount')){
document.getElementById('fedex_number').style.display="none";
document.getElementById('ups_number').style.display="none";
document.getElementById('your_shipping_conditions').style.display="none";
var shipping_method = document.getElementById('text-freeamount').innerText;
document.getElementById('text-shipping').innerHTML = shipping_method;
var shipping_value = document.getElementById('value-freeamount').innerText;
document.getElementById('value-shipping').innerHTML = shipping_value;
}
});
While this JavaScript works fine on initial page load, it fails to work on the returned results, which contain identical HTML as the initial page load. It seems like a binding issue. Any suggestions on how to implement it so that the JavaScript functions correctly on the returned results?