How to modify my jQuery script to add a math function and pass the result?
How to modify my jQuery script to add a math function and pass the result?
You can find my jQuery in this fiddle http://jsfiddle.net/qSkZW/9/ where the value changes based on your dropdown selection.
What I need is to multiply the selected quantity with a PHP variable. For example when$price = '10';
and you select 3 for quantity, you get an output of 30.
Also, how can I pass the result to display it in the next page ?
Thank you.
What I am trying to clone is the Your Purchase system found here https://www.groupon.com/deals/pizza-delight/confirmation?ms=false&pledge_id=538463 that you add the quantity and you get the final price.
Answer by helloandre for How to modify my jQuery script to add a math function and pass the result?
You can just echo onto the page in your javascript:
Answer by karim79 for How to modify my jQuery script to add a math function and pass the result?
$("#quantity").change(function () { var str = $(this).val(); $("#here").text(parseInt(str, 10) * ); }).change();
Answer by John Himmelman for How to modify my jQuery script to add a math function and pass the result?
The simplest method is to store the php value in a js variable - which you can reference in your js function. Eg...
In addition you can encode php vars as json for easy js access. Eg...
array( 'price' => 10, 'description' => 'These socks are steaming HOT!', ), 'Cool socks' => array( 'price' => 20, 'description' => 'The perfect treat for for feet on those hot summer days!', ), ); ?>
edit: example is scarf compatible
Answer by Lo?s Di Qual for How to modify my jQuery script to add a math function and pass the result?
You can use HTML5 custom attributes:
And then get it with jQuery:
$("#quantity").change(function () { var el = $(this); var str = el.val() * el.attr('data-price'); $("#here").text(str); }) .change();
Storing it in a var price
value is not a good solution as it doesn't specify a select element.
Answer by Paulpro for How to modify my jQuery script to add a math function and pass the result?
Just output the integer directly into the script using php:
$("#quantity").change(function () { var price = parseInt($(this).val(), 10)* $("#here").text(price); }).change();
Using PHP 5.4 or short tags enabled:
var price = parseInt($(this).val(), 10)*
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment