get data from db to set as default in dropdown list created using jquery
- here is my below code create the dropdown using jquery. but what i need to do set default selection on this type of jquery creation based on mysql value. i did with this following code but its not working.please help me guyz..
-
-
- <script>
- $('#orderbox2' + categories).text('Currency Notes'); //its not working for default selection)
-
- categories = {
- "Select":[{value:'select',text:'Select'}],
- "United States":[{value:'<?php echo 1;?>', text:'Select'},{value:'<?php echo usa;?>', text:'Currency'},{value:'<?php echo usa; ?>', text:'Forex'},{value:'<?php echo usa; ?>', text:'Travells}],
- "European":[{value:'<?php echo 2;?>', text:'Select'},{value:'<?php echo eur;?>', text:'Currency '},{value:'<?php echo eur; ?>', text:'Forex},{value:'<?php echo eur; ?>', text:'Travells'}],
- "Britian":[{value:'<?php echo 3?>', text:'Select'},{value:'<?php echo gbp;?>', text:'Currency'},{value:'<?php echo gbp; ?>', text:'Forex'}
- };
-
- 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>