We inherited some old code which is in place and working. It is a simple pricing switch between £ GBP and $ USD - the price updates onChange as seen below in the pen.
PEN link
https://codepen.io/go6/pen/rNOgaee
$(function() {
$("#curr").on("change",function() {
var curr = this.value;
var prefix = curr=="500"; // or ["usd","yen",...].indexOf(curr); for more
var sign = curr=="500"?"":"";
$(".value").each(function(){
$(this).text(
(prefix?sign:"") +
$(this).data(curr) +
(prefix?sign:"")
);
})
}).change();
});
Question
The price by default is set to USD, as per the data-usd value when the page loads. We want to supply a page URL query string eg /pricing?curr=GBP which can toggle the pricing to GBP.
Tried so far but not working
I have tried a few combinations using this Answer:
Show / Hide elements based on query string value
but so far, none have worked. Please can someone assist in implementing a query string sitch of currency?