javascript - How to auto select a particular option -


my site uses currency converter (shopify) , though store accepts gbp want auto-select currency usd upon entereing site, prices converted usd

the following currency converter code

<label for="currencies">currency converter </label> <select id="currencies" name="currencies">   {% capture codes     %},usd,eur,gbp,cad,ars,aud,bbd,bdt,bsd,bhd,brl,bob,bnd,bgn,mmk,kyd,clp,cny,cop,crc,hrk,czk,dkk    ,dop,xcd,egp,xpf,fjd,ghs,gtq,gyd,gel,hkd,huf,isk,inr,idr,nis,jmd,jpy,jod,kzt,kes,kwd,lvl,ltl,m    xn,myr,mur,mdl,mad,mnt,mzn,ang,nzd,ngn,nok,omr,pkr,pyg,pen,php,pln,qar,ron,rub,sar,rsd,scr,sgd    ,syp,zar,krw,lkr,sek,chf,twd,thb,tzs,ttd,try,uah,aed,uyu,veb,vnd,zmk,{% endcapture %}   {% assign supported_codes = settings.supported_currencies | split: ' ' %}   <option value="{{ shop.currency }}" selected="selected">{{ shop.currency }}</option>   {% code in supported_codes %}     {% if code != shop.currency , codes contains code %}    <option value="{{ code }}">{{ code }}</option>     {% endif %}   {% endfor %} </select> 

how can auto-select usd show?

you javascript this:

http://jsfiddle.net/83whb/

basically want run script onload sets value of currencies usd.

ideally you'd wanna run script onload, or right after select element rendered.

<script> document.getelementbyid('currencies').value = "usd"; //console.log('current value selected: ' + document.getelementbyid('currencies').value); </script> 

alternatively (and better), server side this:

<label for="currencies">currency converter </label> <select id="currencies" name="currencies">     {% capture codes %},usd,eur,gbp,cad,ars,aud,bbd,bdt,bsd,bhd,brl,bob,bnd,bgn,mmk,kyd,clp,cny,cop,crc,hrk,czk,dkk    ,dop,xcd,egp,xpf,fjd,ghs,gtq,gyd,gel,hkd,huf,isk,inr,idr,nis,jmd,jpy,jod,kzt,kes,kwd,lvl,ltl,m    xn,myr,mur,mdl,mad,mnt,mzn,ang,nzd,ngn,nok,omr,pkr,pyg,pen,php,pln,qar,ron,rub,sar,rsd,scr,sgd    ,syp,zar,krw,lkr,sek,chf,twd,thb,tzs,ttd,try,uah,aed,uyu,veb,vnd,zmk,{% endcapture %}       {% assign supported_codes = settings.supported_currencies | split: ' ' %}       <option value="{{ shop.currency }}" >{{ shop.currency }}</option>       {% code in supported_codes %}         {% if code != shop.currency , codes contains code %}            {% if code == 'usd' %}               <option value="{{ code }}" selected="selected"> {{ code }}</option>            {% else %}               <option value="{{ code }}">{{ code }}</option>            {% endif %}          {% endif %}       {% endfor %} </select> 

Comments

  1. It’s really interesting, looking forward to more updates and posts on the same.
    Gold And Silver Dealers In San Francisco

    ReplyDelete

Post a Comment

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -