I am in a mobile app and I use an input field in order user submit a number.
When I go back and return to the page that input field present the latest number input displayed at the input field.
Is there any way to clear the field every time the page load?
$('#shares').keyup(function(){
payment = 0;
calcTotal();
gtotal = ($('#shares').val() * 1) + payment;
gtotal = gtotal.toFixed(2);
$("p.total").html("Total Payment: <strong>" + gtotal + "</strong>");
});
Setting
val('')
will empty the input field. So you would use this:Clear the input field when the page loads:
You can clear the input field by using
$('#shares').val('');
Since you are using jQuery, how about using a trigger-reset:
if you hit the "back" button it usually tends to stick, what you can do is when the form is submitted clear the element then before it goes to the next page but after doing with the element what you need to.
While submitting form use reset method on form. The reset() method resets the values of all elements in a form.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/reset