I tried to pass the value of variable from one function to another
function changeParent(){
$(document).ready(function(){
$('a').on('click',function() {
var x = $(this).attr('id');
var y = $(this).attr('name');
$.ajax({
type: 'POST',
url: 'http://test.local/Family.php?action=getId',
data: {'childId' : y},
success: function(msg) {
document.getElementById('names').value = x;
msg = x ;
}
});
});
});
}
The second function that calls msg from the first function
$(document).ready(function(){
$('#saveId').on('click',function() {
alert(msg);
});
});
I tried
alert(window.msg);
but it didn't get the last value in msg. How I can pass it?
$('#saveId').on('click',function() {alert(document.getElementById('names').value); });