jquery - Have a radio button as a check for base value -


i've worked through code, , i've ended having 2 possible base prices. students base = $249.99 , assistants = $399.99.

each option has choice add:

a chair $99.99 and/or desk $99.99.

as of right code not recognize assistants option($399.99), nor proper math. in all: if assistants option selected, supposed replaced new base price.

how base price switch between 2 choices , recognize checkbox values?

i've made fiddle better display i'm working with.

thank in advance.

// check if assistant or student $('input[name=type]').on('change', function(){     if($(this).prop('value') == 1) {         // if assistant         var originalamount = 399.99;         $('span.amount').html(originalamount);     }else {         // else student         var originalamount = 249.99;         $('span.amount').html(originalamount);     } }); // check current amount originalamount = number($('span.amount').html().replace(/[^0-9\.]+/g,"")); $(':checkbox').change(function(){     sum = originalamount;     var names = $(':checked').map(function(){         sum += (this.value - 0);         return this.name;     }).get().join(',');     $('span.amount').text('$' + sum);     spans[1].innerhtml = sum; }); 

here working fiddle:

http://jsfiddle.net/3snfy/18/

basically, change originalamount originalamount in

$('span.amount').html(originalamount); 

also, you'd want declare variable @ global level maths work right.

edit: updated fiddle account radio button change along selection of checkboxes.

http://jsfiddle.net/3snfy/19/


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -