Skip to content
Advertisement

How do I set the selected item in a drop down box

Is there any way to set the selected item in a drop down box using the following ‘type’ code?

JavaScript

The database holds a month.. and I want to allow on the edit page, them to choose this month.. but it to be pre-filled with their current setting?

Advertisement

Answer

You need to set the selected attribute of the correct option tag:

JavaScript

Your PHP would look something like this:

JavaScript

I usually find it neater to create an array of values and loop through that to create a dropdown.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement