Jump to content

php javascript


Danny620

Recommended Posts

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);
        }

    }

Link to comment
https://forums.phpfreaks.com/topic/256607-php-javascript/
Share on other sites

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)

Link to comment
https://forums.phpfreaks.com/topic/256607-php-javascript/#findComment-1315640
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.