javascript - Using custom attribute jQuery selectors with dropdown select (take 2) -


this issue making me want smash computer. have form, want calculate values selections on form. have 2 jsfiddles here, want have can make selections, calculate on click. can't form work on click. other fiddle uses on change , keyup functions. there issue on form well. if change first select "option 2", you'll see value select ends being "1.379999999996" instead of "1.38". why happening?

fiddle click function js:

$('#submit').click(function(){     var price=$(this).find("option:selected").attr('data-price');         var ink=$('#ink').val();        var loc1=$('#loc1').val();     var res= price*1 + ink*1 + loc1*1 ;      $('#bleh').val( res || 0 ); }); 

fiddle change , keyup functions js:

$('#ink, #loc1, .sel').on('keyup change',function(){     var price=$('option:selected', this).attr('data-price');     var ink=$('#ink').val();        var loc1=$('#loc1').val();         var res= price*1 + ink*1 + loc1*1 ;      $('#bleh').val( res || 0 ); }); 

your selector $(this).find("option:selected") wrong this here points #submit button, need find out select element using id #style

$('#submit').click(function(){     var price=$('#style').find("option:selected").attr('data-price');         var ink=$('#ink').val();        var loc1=$('#loc1').val();     var res= price*1 + ink*1 + loc1*1 ;      $('#bleh').val( res || 0 ); }); 

demo: fiddle


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -