Reputation: 133
I'm working on a deposit form. The form has a main content section where a user can select from a number of different forms of deposit. Each of the different forms of deposit runs a script that auto formats the currency to 0.00 left to right, so if the user is depositing $25, they would type 2500 and the input field displays 25.00.
Where I'm running into an issue is clearing the input field if the user changes her mind on the deposit method after entering an amount. If the user goes back to the main content and chooses another deposit method, when she clicks in the empty amount field for the new method and begins to type, the previous amount is populated and anything new entered is appended. (i.e. 25.00 becomes 250.25). Obviously this is not optimal. I have a fiddle set up for demonstration purposes.
What I am trying to do is to clear the value entered in the input field if the user clicks the "change" option on the deposit method.
$('.back-txt').click(function() {
$('#main-content').show();
$('#ach-content, #other-content1, #other-content2').hide();
$('.titletext').html("Choose A Deposit Method");
// Clearing input
$("input[type='text']").val('');
});
I've tried multiple variations of:
$("input[type='text']").val('');
Including targeting just inpput, "#amount", and the class ".mib".
I think I'm on the right track, but maybe I'm not targeting the write element?
Upvotes: 0
Views: 43
Reputation: 466
I see 2 main problems in your code:
FIRST: even the inputs are visible singolarly, you cannot give them the same id
, so change it.
SECOND: you are trying to select input[type"text"]
but tou have type="tel"
in all inputs. Try to fix them first, then let us know.
EDIT
I've found the real problem, the above are important too, but your problem is the input
variable: just let it global, and reset it with the input
field.
Upvotes: 1