set a default selection on select box dropdown list using jquery.
Here this is my for following code for creating dependent select box using jquery.
what i am exactly needed is how to set default selection of dropdown,I am struggle on this selection.Please help me guys...
-
- var categories = {
- "Select":[{value:'select',text:'Select'}],
-
- "United States":[{value:'0', text:'Select'},{value:'55', text:'Currency'},{value:'67', text:'Card'},{value:'56', text:'Cheque'}],
- "European":[{value:'0', text:'Select'},{value:'30', text:'Currency'},{value:'40', text:'Card'},{value:'50', text:'Cheque'}],
- "Britian":[{value:'0', text:'Select'},{value:'10', text:'Currency'},{value:'20', text:' Card'},{value:'30, text:'Cheque'}],
- "Australia":[{value:'0', text:'Select'},{value:'1', text:'Currency Notes'},{value:'2', text:'Card'},{value:'3', text:'Cheque'}],
- };
-
- function selectchange($this) {
- var select = $this.parents('.product-item').find('.orderbox2');
- select.empty();
- $.each(categories[$(':selected', $this).text()], function () {
- select.append('<option value="' + this.value + '">' + this.text + '</option>');
- });
- }
-
- $(function () {
- $("#product").on("change", '.orderbox1', function() { selectchange($(this)) });
- $("#product").append(categories);
- });
- </script>
- <body>
- <DIV class="product-item>
- <div>
-
- <select name="item_currency[]" id="orderbox1" class="orderbox1" >
- <option value="">Select</option>
- <option value="usa">United states</option>
-
- <option value="gbp">Britian</option>
-
- <option value="eur">European</option>
- </div
- <div>
-
- <select name="item_size[]" id="orderbox2" class="orderbox2" >
</select>
</div>
</div>