jquery - Whats wrong with my if statement -


i have simple script basic calculations. have price dynamically populated sake of simplicity set constant price. input box takes down payment has min , max attributes set. min 10% of 3000 300 , max 3000. if statement keeps telling me down payment either less or more min max values unless use min or max values. in fiddle if statement works min , max not on actual site. here fiddle check.

html

<table>   <tr id="payment">     <td>payment</td>     <td>$3000</td>   </tr>   <tr id="down_payment">     <td>down payment</td>     <td>$300</td>   </tr>   <tr id="financed_amount">     <td>amount financed</td>     <td>$2700</td>   </tr>   <tr id="term">     <td>term</td>     <td>22 months</td>   </tr>   <tr id="interest_rate">     <td>interest rate</td>     <td>0%</td>   </tr>   <tr id="monthly_payment">     <td>monthly payment</td>     <td>$122.73</td>   </tr>   <tr>     <td colspan="2">&nbsp;</td>   </tr>   <tr>     <td colspan="2">       <h5 style="font-size: .9em; text-align: center">enter higher down payment lower monthly payment</h5></td>   </tr>   <tr id="update_button">     <td>       <input type="number" value="" min="300" max="3000" name="change_amount" id="change_amount" style="width:100px; margin-left: 24%;" />       <br>       <label for="change_amount" class="error" style="display:none;margin-left: 10%;"></label>     </td>     <td>       <input type="button" value="update" name="update_down_payment" id="update_down_payment" />     </td>   </tr> </table> 

js

$('#update_down_payment').click(function(e) {   var down_payment = $('#change_amount').val();   var min = $('#change_amount').attr('min');   var max = $('#change_amount').attr('max');   alert('down payment=' + down_payment + ' min=' + min + ' max=' + max);   if (down_payment === "" || down_payment > max || down_payment < min) {     $('.error').text("please input down payment between " + number(min).tolocalestring("en-us", {       style: "currency",       currency: "usd",       minimumfractiondigits: 0     }) + " , " + number(max).tolocalestring("en-us", {       style: "currency",       currency: "usd",       minimumfractiondigits: 0     }));     $('.error').show();   } else {     var payment = $("#payment td:nth-child(2)").text().replace(/\d/g, '') * 1;     var financed_amount = (payment - down_payment);     $('.error').hide();     $('#down_payment td:nth-child(2)').text(number(down_payment).tolocalestring("en-us", {       style: "currency",       currency: "usd",       minimumfractiondigits: 0     }));     $('#financed_amount td:nth-child(2)').text(number(financed_amount).tolocalestring("en-us", {       style: "currency",       currency: "usd",       minimumfractiondigits: 0     }));     $('#monthly_payment td:nth-child(2)').text(number(financed_amount / 22).tolocalestring("en-us", {       style: "currency",       currency: "usd",       minimumfractiondigits: 0     }));   } }); 

is wrong if statement

this make work

  var min = parseint($('#change_amount').attr('min'),10);   var max = parseint($('#change_amount').attr('max'),10); 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -