Reputation: 17
I have a drop down list here :
can't I avoid using the (Distributor) and the (Public) buttons and just show a text automatically appears under the table ?
and if I can't .. can I just add (CHF) beside the number that appears in the message ?
that's the jquery I use
eval( $( 'td:nth-child(3)' ).map( function( td, $this ){
return ( ( parseFloat( ( $this = $( this ) ).text() ) || 0 )
* ( parseFloat( $this.parent().find( 'select' ).val() ) || 0 ) );
} ).get().join( '+' ) )
Please explain in details cuz I'm super beginner
Upvotes: 0
Views: 224
Reputation: 191729
Instead of using onclick
for the Distributor/Public buttons, you can just update the table (or alert) on the change event of the dropdowns. The only thing is that how do you know whether they are calculating with "Distributor" or "Public?"
$(".pricestable select").on('change', calculate);
I suppose that "Distributor" and "Public" could be radio buttons, and you could make the decision based on that:
$(".pricestable select").on('change', function () {
if ($("#distributor").prop('checked')) {
calculate();
}
else {
calculate2();
}
});
I also advise against using eval
-- you can just iterate over the arrays and add them using +
instead of evaluating the string with +
es.
Upvotes: 1