Hi I have a bit of code which once you select drop value the price field updates

3 or more selected from drop down price = £10.99 each 2 price = £11.99 each 1 price = £12.99 each

jQuery(document).ready( function(){

        var map = [ '12.99', '11.99', '10.99' ];

        jQuery('#payslips-required').change(function(){

            var o = parseInt($(this).val()) < 3 ? jQuery(this).val()-1 : 2;

            jQuery('#price').val(map[o]).addClass('hidden');

        });

    });

Currently the above works but when I add a total field right next to it and amend the jQuery to work out the total, price x number selected

Here is the example in action http://jsfiddle.net/U92fq/1/ which works

but when I place the added code which is

var price = $('#price').val()   
            var quantity = $('#payslips-required').val()    
            var total = price * quantity;
            jQuery('#total').val(total).addClass('hidden');

Into into the original code does not work when it clearly does on the jsfiddle link provided both the price and total do not display.

Just can't see why it does not work.

Summary: Need to get the total to work.

Note: using this on Wordpress with Contact form 7 plugin can be seen here http://payslips4u.co.uk/order-monthly-payslips/

有帮助吗?

解决方案

Use semicolon end of each line

 jQuery('#price').val(map[o]).addClass('hidden');
            var price = $('#price').val();  
            var quantity = $('#payslips-required').val();   
            var total = price * quantity;
            jQuery('#total').val(total).addClass('hidden');

其他提示

Either use semicolon (;) at the end of each var or put one var with comma seperation

var price = $('#price').val(),  
    quantity = $('#payslips-required').val(),   
    total = price * quantity;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top