Danny620 Posted February 7, 2012 Share Posted February 7, 2012 I Have a javascript function that builds a option list on the fly i.e like <select style="padding-top:6px; padding-left:5px" id="model2" name="Model"> <option value="500">500</option> <option value="500C">500C</option> <option value="Grande Punto">Grande Punto</option> <option value="Punto Evo">Punto Evo</option> <option value="Other">Other</option></select> echo '<script type="application/javascript"> $(document).ready(function() { $("#make2 option[value=\''.$manufacturer.'\']").attr(\'selected\', \'selected\'); this should set Punto evo as seleted but its not doing $("#model2 option[value=\'Punto Evo\']").attr(\'selected\', \'selected\'); var makeDropdown3 = document.getElementById(\'make2\'); setModel2(makeDropdown3.selectedIndex); }); </script>'; this should set Punto evo as seleted but its not doing heres the function that creates the selete option on the fly function setModel2(index) { var modelDropdown = document.getElementById('model2'); modelDropdown.options.length = null; for(var i = 0; i < model[index].length; i++) { modelDropdown.options[i] = new Option(model[index][i],model[index][i]); } } window.onload = function() { var makeDropdown = document.getElementById('make'); makeDropdown.onchange = function() { setModel(this.selectedIndex); } var makeDropdown2 = document.getElementById('make2'); makeDropdown2.onchange = function() { setModel2(this.selectedIndex); } } Quote Link to comment https://forums.phpfreaks.com/topic/256607-php-javascript/ Share on other sites More sharing options...
nogray Posted February 8, 2012 Share Posted February 8, 2012 Changing the selected value in the option after the menu is created won't do anything. You need to change the select menu selectedIndex to the option index (e.g. loop through the options and compare values, when you have a match set the selectedIndex to i) Quote Link to comment https://forums.phpfreaks.com/topic/256607-php-javascript/#findComment-1315640 Share on other sites More sharing options...
haku Posted February 8, 2012 Share Posted February 8, 2012 Incorrect reply removed. Quote Link to comment https://forums.phpfreaks.com/topic/256607-php-javascript/#findComment-1315647 Share on other sites More sharing options...
Danny620 Posted February 8, 2012 Author Share Posted February 8, 2012 Can you show me any code? Quote Link to comment https://forums.phpfreaks.com/topic/256607-php-javascript/#findComment-1315763 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.