Tuesday, 10 September 2013

jQuery if input text equals var do something

jQuery if input text equals var do something

I have a form that calculates the sum of several input values (checkboxes
and dropdowns - not user entered values). At the bottom of the form I have
a "Discount Code" box, I want to be able to enter a code and it takes a
set amount off the total.
With my code I am trying to say, if text entered = discount code, change
the value of the input to 50. Here is what I have so far
var discountCode = 'DISTR50';
var codeEntered = $("input[name='discount']");
if (discountCode = codeEntered) {
$('#discount input').attr('value',50);
}
and for the html:
<input type="text" id="discount" name="discount" class="txt"/>

No comments:

Post a Comment