Reputation: 61
Is there a way to change the content of a form with Javascript?
I have a series of paypal buttons, but want the user to be able to shop in CAD or USD.
The form looks something like this:
<form onsubmit="return false;">
<input name="amount" value="6.99" type="hidden" />
<input name="currency_code" value="CAD" type="hidden" />
</form>
I need to change the value="CAD' to value="USD"
Is there any way I could have a button or some sort of 'toggle' on the site whereby users can change the currency? It should happen to each product.
I had someone implement simple cart, but they are no longer available
is there a better way to do this?( I though this might be simplest) But perhaps it should be done during checkout somehow? I presume this would be more complicated.
thanks in advance and hope I have been clear! let me know if you need more information.
my site is www.bodesi.com (if that helps)
Upvotes: 1
Views: 109
Reputation: 803
If I have understood you requirement properly , Ask user somewhere for the currency
<select name = "currency" id='currency' >
<option value='USD'>USD</option>
<option value='CAD'>CAD</option>
</select>
And later use the javascript on the same page to change the value of the paypal button
If you are using jquery:
(function($){
$("#currency").change(function(){
$('input[name="currency_code"]').val($(this).val());
});
})(jQuery);
If you want to use clean javascript then
document.getElementById('currency').onchange = function(){
document.getElementsByName('currency_code')[0].value= this.value;
}
Upvotes: 0
Reputation: 144
You can do it via javascript DOM.
Example: <input type="button" onclick="document.getElementsByName('currency_code')[0].value='USD';">
Upvotes: 2
Reputation: 1461
You can do this easily with jQuery, which it looks like your site already includes.
Here's one way to do it: http://jsfiddle.net/x7LDN/
$(function() {
$('#change_currency').click(function(){
$('input[name="currency_code"]').val('USD');
});
});
Upvotes: 0