user2093601
user2093601

Reputation: 402

How to use javascript to get input and put it on the page

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.

Upvotes: 0

Views: 51

Answers (2)

Ashish Kumar
Ashish Kumar

Reputation: 3039

Try this:

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

Working Demo on : JS Fiddle

Upvotes: 1

SeeTheC
SeeTheC

Reputation: 1631

try on onChange event :

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

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

});

Upvotes: 0

Related Questions