Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.