im using this code to replace <div id="replaceit"></div>
with content in my dynamic url
but it does not instant update when i change select option.
how can i make it work.
Thank you!
$(document).ready(function() {
function updatePreview() {
var year = $("#year").val();
var month = $("#month").val();
var dynamicUrl = "print.php?year=" + year + "&month=" + month;
$.get(dynamicUrl, function(data) {
$("#replaceit").replaceWith(data);
}).fail(function() {
alert("Failed to fetch preview content. Please try again.");
});
}
$('#year, #month').on('change', function(){
updatePreview();
});
updatePreview();
});
2
Answers
replaceWith
removes the selected elements from the dom. I think yuo want to replace the contents of the element, to do this use.html()
Try Like this
STEP 1 : set the HTML like this
STEP 2 : Replace your JavaScript code with the following code