javascript - How To use js variable into another file -
i have javascript variable has value on-change. want use variable in file calculation.
for example have variable in index.php follow:
$(function() { $("#sel").on("change", function() { var vall = $(this).find('option:selected').attr('value') alert(vall); }); });
and in file calculate.php have code , want use "vall" variable multiple "$total variable"
public function getgrandtotal(){ $quote = mage::getmodel('checkout/session')->getquote(); $total = $quote->getgrandtotal(); $gt = $total * var vall ; // "vall" variable multiply total return mage::helper('checkout')->formatprice($gt); }
that should done ajax like:
$("#sel").on("change", function() { var vall = $(this).val(); $.ajax({ type:'post', url : "url call", data:{val : vall}, // send vall here val in backend. datatype:'text', // other values json, script, html etc. success:function(data){ console.log(data); // <----get response backend if echoed. } }); });
Comments
Post a Comment