1

I have some third party gadget on my wordpress website and getting below code but it's giving me default currency for example JPY Japanese but I want to switch using Javascript and select USD from the list how I can implement some script which can select value="USD" when page load, I don't want manual USD selection all the time, when visitor want to change the currency they can change it from the list but I want to present default selection value as a USD. Javascript or php any method for wordpress or normal html code where I can select default value as USD.

<div class="currencyId">
<span class="label">
<span>Currency</span>
</span>
<span>
<select rel="currencyId" value="JPY" style="width: 124px;">
<option value="JPY">Japanese yen (JPY)</option></br>
<option value="AFN">Afghan afghani (AFN)</option></br>
<option value="ALL">Albanian lek (ALL)</option></br>
<option value="DZD">Algerian dinar (DZD)</option></br>
<option value="AOA">Angolan kwanza (AOA)</option></br>
<option value="ARS">Argentine peso (ARS)</option></br>
<option value="AMD">Armenian dram (AMD)</option></br>
<option value="AWG">Aruban florin (AWG)</option></br>
<option value="USD">United States dollar (USD)</option></br>
</select>
</span>
</div>

Waiting for some favorable reply. I want to implement code between

Group Of Oceninfo
  • 358
  • 2
  • 3
  • 19
  • check here on how to replace existing options -- http://stackoverflow.com/questions/1801499/how-to-change-options-of-select-with-jquery – Tasos Sep 10 '16 at 10:48

1 Answers1

0

using this you can change the value of select box when page loads

jQuery(document).ready(function($){
  $('select').find('option[value=USD]').attr('selected','selected');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<select>
   <option value="JPY">Japanese yen (JPY)</option>
<option value="AFN">Afghan afghani (AFN)</option>
<option value="ALL">Albanian lek (ALL)</option>
<option value="DZD">Algerian dinar (DZD)</option>
<option value="AOA">Angolan kwanza (AOA)</option>
<option value="ARS">Argentine peso (ARS)</option>
<option value="AMD">Armenian dram (AMD)</option>
<option value="AWG">Aruban florin (AWG)</option>
<option value="USD">United States dollar (USD)</option>
</select>
Ganesh Putta
  • 2,622
  • 2
  • 19
  • 26
  • It might be better to use the following query: $('#currencyId select').find('option[value=USD]').attr('selected','selected'); otherwise the code will target all select tags on the page. – ArturoO Sep 10 '16 at 11:57
  • yep ofcourse, it is a very common thing for developers, i think he is aware of this – Ganesh Putta Sep 10 '16 at 12:02