Wednesday, May 16, 2012

How do get change value of <input> element?

I have a input in datalist



<input type="text" value="1" id="txtcount">


I want get new value of it when text change.



I use this code but don't work for me .



<script>
//look no global needed:)

$(document).ready(function(){
// Get the initial value
var $el = $('#txtcount');
$el.data('oldVal', $el.val() );


$el.change(function(){
//store new value
var $this = $(this);
var newValue = $this.data('newVal', $this.val());
})
.focus(function(){
// Get the value when input gains focus
var oldValue = $(this).data('oldVal');
});
});






No comments:

Post a Comment