Jump to content

Product id in javascript


Recommended Posts

Hi,

 

I don't have much experience in js. I want to create variable productId which has got a product ID and then this variable use in

$('#quantity_wanted_'+ productId +').change();

How can I do this ?

<script type="text/javascript">// The button to increment the product value
    //var allowBuyWhenOutOfStock = false;
    
$(document).on('click', '.product_quantity_up', function(e){
        var productId = 6;
        e.preventDefault();
        fieldName = $(this).data('field-qty');
        var currentVal = parseInt($('input[name='+fieldName+']').val());
        if (!allowBuyWhenOutOfStock && quantityAvailable > 0)
                quantityAvailableT = quantityAvailable;
        else
                quantityAvailableT = 100000000;
        if (!isNaN(currentVal) && currentVal < quantityAvailableT)
                $('input[name='+fieldName+']').val(currentVal + 1).trigger('keyup');
        else
                $('input[name='+fieldName+']').val(quantityAvailableT);

        $('#quantity_wanted_'+ productId +').change();
});
 // The button to decrement the product value
$(document).on('click', '.product_quantity_down', function(e){
    var productId = 7;
        e.preventDefault();
        fieldName = $(this).data('field-qty');
        var currentVal = parseInt($('input[name='+fieldName+']').val());
        if (!isNaN(currentVal) && currentVal > 1)
                $('input[name='+fieldName+']').val(currentVal - 1).trigger('keyup');
        else
                $('input[name='+fieldName+']').val(1);

        $('#quantity_wanted_'+productId+').change();
});</script>

Kind regards

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...