Possible Duplicate:
Function triggering early
I have whipped up this code, but why on earth would it be alerting me that its undefined even though I have never even got a chance to click on and select a date from the UI date picker when I call the function test()?
Doesn't seem to make sense with me?
var sdate
function test() {
alert(select_date())
}
function select_date() {
$('#dd').dialog({
autoOpen: true,
modal: true,
overlay: {
opacity: 0.5,
background: 'black'
},
title: "title",
height: 265,
width: 235,
draggable: false,
resizable: false
}); //end of dialog
$('#d1').datepicker({
onSelect: function() {
sdate = $(this).val();
$("#dd").dialog("close");
}
});
return sdate
}