1

I need your help,

How can the code below be modified such that when a date is selected, that it will store the selected date into (var z) and then its value can be called back later. I can't seem to figure this out, it should be simple, and right by eyes. What am I doing wrong?

<html>

<head>

<!-- LOAD JQUERY LIBRARY: -->  
    <link   href="jq/jquery-ui.css"         type="text/css" rel="stylesheet" />
    <script src="jq/jquery.min.js"          type="text/javascript"> </script>
    <script src="jq/jquery-ui.min.js"       type="text/javascript"> </script>

<script type="text/javascript">
var z

window.onload = function() {


                $('#dd').dialog({ 
                                    autoOpen:   true,
                                    modal:      true,
                                    overlay:    { opacity: 0.5, background: 'black'},
                                    title:      'Select the date:',
                                    height:     215, 
                                    width:      234,
                                    draggable:  false, 
                                    resizable:  false

                });//end of dialog_atip


$('#d1').datepicker({
            onSelect:function(){
                    z = $(this).val()
                    alert(z)
                    $("#dd").dialog("close")
            }

});




}//end of window.onload

function callback() { alert(z) }

</script>


</head>

<body>
<div style="display:none" id="dd">
<div id="d1">
</div>

</div>
<p><input onlick="callback()" type="submit" value="Submit" name="B1"></p>

</body>

</html>
Jason Kelly
  • 2,539
  • 10
  • 43
  • 80

2 Answers2

1

There are too many missing semicolons in your code. Plus , In spite of putting in window.onload put your code in $(document).ready(function() { }); .

I made some changes in your code. Its working now.

Have a loot at This.

I think this is exactly what you are asking for.

ygssoni
  • 7,219
  • 2
  • 23
  • 24
0

There seem to be a few things going on. The onclick was mispelled, and as was pointed out - semicolons were missing. This should work.

<script type="text/javascript">
var z;

$(document).ready(function() {
  $('#dd').dialog({ 
       autoOpen:   true,
       modal:      true,
       overlay:    { opacity: 0.5, background: 'black'},
       title:      'Select the date:',
       height:     215, 
       width:      234,
       draggable:  false, 
       resizable:  false

   });//end of dialog_atip


  $("#B1").click(function(){ 
        callback();
  });

  $('#d1').datepicker({
     onSelect:function(){
                    z = $(this).val();
                    alert(z);
                    $("#dd").dialog("close");
     }
  });

});//end of window.onload


function callback() { 
    alert(z);
}
</script>

I also modified the input button to:

<input type="button" value="Submit" name="B1" id="B1">

And you can also play around with the fiddle, here: http://jsfiddle.net/jE8tL/

jcern
  • 7,798
  • 4
  • 39
  • 47
  • Works great! Thanks so much for everybody's help. Glad to have found you here on these forums. Kind and many thanks for everyones help. Its too bad you can't select more than one answer, because there are many ways to skin a cat lol – Jason Kelly Aug 29 '12 at 19:57