0

I have the code below to get a date from a user and then put it in a variable but how do I add an event that once the user picks a date to then add it on the screen.

<div class="container" >
    <div>
      <h1>Welcome to this site</h1>
      <p>Please select a date below.</p>
      <p>Click Here: <input type="text" name="date" id="datepicker" /><p> 
</div>
<div id='test'>
</div>

<script>
$("#datepicker").datepicker();
$("#datepicker").bind("change", function () {
    $("#test").text($(this).val());
});
</script>

The code works this way.

0

2 Answers 2

1

Try this:

$("#datepicker").bind("change", function () {
    $("#test").text($(this).val());
});

Working Demo on : JS Fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

As mentioned below, as of jQuery 1.7 you should use on() instead of bind().
0

try on onChange event :

 var dateSelected ;
$("#datepicker").bind("change",function(){ 

 //.. your code
  dateSelected = document.getElementById('datepicker').value;

});

3 Comments

.bind() is outdated. As of jQuery 1.7, on() is the preferred method.
I'm trying to figure it out but what code of mine would I put into the 'your code' part?
As per you functionality , as this method is called whenever date is changed .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.