This is simple question regarding javascript .value and .defaultValue
Here is my First html
<input id="txt" value="Hello">
</input>
<input type="button" id="btn" />
And corresponding js
$('#btn').click(function(){
alert('Old Value '+ document.getElementById('txt').defaultValue);
alert('New value ' + document.getElementById('txt').value);
});
So the above html by default has Hello, now if i remove a few characters and make it Hel and press the button, the output that i'm getting is Old Value Hello and New value Hel
Here is the demo
Now here is my second html
<input id="txt" ></input>
<input type="button" id="btn" />
And the corresponding js
$('#txt').val('Hello');
$('#btn').click(function(){
alert('Old Value '+ document.getElementById('txt').defaultValue);
alert('New value ' + document.getElementById('txt').value);
});
Here if i remove a few characters and make it Hel and press the button, the output that i'm getting is Old Value and New value Hel
Here is the demo
Can any one explain why the difference in defaultValue in both examples
valuein html where in second you don't!:)LOL!<input id="txt" >vs<input id="txt" value="Hello">I reckon!:)