How to implement double currency

/*By Jiangong SUN*/


The principe is get the two price at the same place and switch one to another depending on what you want to display.


You can implement it by using ajax and javascript in your asp.net application.



For example, 

Here is the html code you have, and by default you will show your first price. And the you can use a click to a checkbox for switch on/off your double currency.


<div class="double_currency">
	<input type="checkbox" name="double_currency_checkbox" />
</div>
<div class="switch_value">
	<span class="firstPrice">100 euros</span>
	<span class="secondPrice" style="display:none;">100 dollars</span>
</div>


And in your javascript code, you can switch them by using the following code: 

First define a global variable who can be accessed by any place of you application, and assign it null value.


<script type="text/javascript">
    var globalVars = {};
    //define a variable for double currency
    globalVars.doubleCurrencyActivated = null;  


    $(document).ready(function() {
		
		priceClick();
		
        //Update price for double currency
        if (globalVars.doubleCurrencyActivated == true) {
            $("span.firstPrice").css('display', 'none');
            $("span.secondPrice").css('display', 'block');
        }
        else {
            $("span.firstPrice").css('display', 'block');
            $("span.secondPrice").css('display', 'none');
        }
    });
	
	function priceClick() {
		$('.double_currency input:checkbox').bind('click', function() {
			if ($('.double_currency input:checked').length == 1) {
				globalVars.doubleCurrencyActivated = true;
			} else {
				globalVars.doubleCurrencyActivated = false;
			}
		});
	}
</script>

Bad example :


	if ($('.double_device label input:checked', window.parent.document).length == 1) {
		$("#switch_value").text('<span>100 dollars</span>');
	} else { 
		$("#switch_value").text('<span>100 euros</span>');
	}


So I've show you the principe of implementing double currency in javascript.


You can also do it in ajax when you need to update more than just a div.


Enjoy coding!


你可能感兴趣的:(How to implement double currency)