I have an inputbox where visitors can change the value
<input id="custom_coverage" type="text" value="320" name="custom_coverage">
When they change the value, it makes a calculation on the by another jQuery-script.
How can i add a button or a link next to the input box, so visitors can put it back to the default value?
Store the original value in a data attribute, e.g. <input id="custom_coverage" type="text" value="320" data-original-value="320" name="custom_coverage">
And add a button that switches the values again:
<a href="#" class="restore">Restore</a>
<script>
$(document).on("click", ".restore", function(){
var custom_coverage = $("input#custom_coverage");
custom_coverage.val(custom_coverage.data("original-value"));
});
</script>
Example: http://jsfiddle.net/deDdy/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With