Why can't I get the value of this text input?

Posted by Spilot on Stack Overflow See other posts from Stack Overflow or by Spilot
Published on 2013-06-30T16:02:11Z Indexed on 2013/06/30 16:21 UTC
Read the original article Hit count: 245

Filed under:
|
|

It seems simple enough, but nothing I try is working. I have a jquery ui datepicker, I use val() to get the value of that input on button click(), then log it. The click event is working. I can log a string I write myself, but when I pass console.log() the variable that stores the datepicker value...nothing. I've tried using html() and text() instead of val(), still nothing

//JS

 $(function(){

    $("button").button();
    $("#date").datepicker();

  var date = $("#date").val();

    $("button").click(function(){

// this logs
  console.log("event working");    

// but this logs nothing

        console.log(date);


    });//close click

});//closes function

//HTML
<!DOCTYPE html>
<html>
    <head>
<script src="http://www.parsecdn.com/js/parse-1.2.8.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="http://myDomain/bn/lbStyle.css"/>
<script src="http://myDomain/index.js"></script>

        <title>
            Welcome to The Bringer Network
        </title>
    </head>

    <body>

        <form id="dialog">

        <p>Date <input type="text" id="date"/></p>

         <button>Submit</button>

        </form>
    </body>
</html>

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jquery-ui