I have been working with Gilbert Pellegrom JQuery Currency plugin, to convert prices on oru website into the visitor’s desired currency. I have worked out how to trigger it upon change of the region select, but can’t quite sort out how to remember the new currency in the script.
My select is:
<select id="sb" name="region">
<option value="USD" selected="selected"> US$ </option>
<option value="CAD"> CAD$ </option>
<option value="GBP"> UK £</option>
<option value="EUR"> EURO</option>
</select>
The script call is:
<script type="text/javascript">
$('#sb').change( function() {
var reg = $(this).val();
$('.convert').currency({ region: reg, convertFrom: 'USD', convertLocation: 'include/convert.php', decimals: '0' });
});
</script>
The goal is to some how cause the value – convertFrom: ‘USD’ to change to the currency chosen from the select AFTER the conversion script has run it’s course.
The JQuery plugin, runs through the page finds any span with the convert class and performs the conversion. It uses a php file to do the actual calculating, I thought about using a cookie on the php file, but that would change with the first price converted and all subsequent ones would have the wrong value.
Try defining a global variable to store the
convertFromvalue outside the change function. Then set it to the selected value after the currency calculator has run its course:That should do it.