Yekver Yekver - 6 months ago 29
MySQL Question

Jquery form get default values

If I have code like this:

<form id="test_form">
<input type="text" value="Original value" />
</form>


Then using jQuery I run this code:

$('#test_form input').val('New value');


So input have new value, but I wanna get the old one, so I do:

$('#test_form')[0].reset();


now
$('#test_form input').val() == 'Original value';


But reset method reset all form inputs and restore there default values, so how can I restore default value just in definite input?

Answer

on jQuery 1.6+

$('#test_form input').prop('defaultValue');

on older versions use .attr() instead of .prop()