1

I'm trying to work off of a question that Stefano Zanella answered in the link here. text input value greater than.. jQuery

I need a model to pop up when the shopping cart subtotal is greater than $40.

The code works as long as there is no dollar sign in the subtotal. however, The cart outputs the subtotal with a dollar sign and I don't know how to remove it before calling the alert.

<div id="subtotal-alert"">$55.00</div>

<script>

 $("input[type='text'][name='subtotal-alert']").change(function() {
if ($(this).val() >= 41) {
    alert("To order quantity greater than 40 please use the contact form.");
    $(this).val('');
    $(this).focus();
    }        
});   

Community
  • 1
  • 1
  • 2
    http://stackoverflow.com/questions/559112/how-to-convert-a-currency-string-to-a-double-with-jquery-or-javascript should help you – dbarnes Oct 24 '14 at 21:36
  • There is a small difference between your brief and your code. Actually in that alert you're talking about quantity, not about price – stefanz Oct 24 '14 at 22:51

1 Answers1

1

Use .replace():

$("input[type='text'][name='subtotal-alert']").change(function() {
    if ($(this).val().replace('$','') >= 41) {
        alert("To order quantity greater than 40 please.use the contact form.");
        $(this).val('');
        $(this).focus();
    }        
});
PhilTrep
  • 1,521
  • 1
  • 10
  • 23