0

Hi

I know this can be done, just don't know where to start.

I am creating a site and have a multiple select box in a form

I am going to pass to this form data from a database to be displayed as values. I can do this no problem. But one thing that is frustrating me is I don't know how to pre select the options of the multiple select box based on the results from the database.

e.g

<select name="country[]" multiple="multiple">
        <option>United Kingdom</option>
        <option>United States</option>
        <option>France</option>
        <option>Germany</option>
        <option>Spain</option>
        <option>Italy</option>
    </select>

Lets say that this is the returned data from the country database table But the user can choose to select which countries they want this form applied to so they select UK, USA and France using their mouse. Their submission then gets stored in another table in the database in a field called country.

So when they edit their submission it gathers their response data from the response table and builds the form values based on their submission

so for instance their name field will go from

<input type="text" name="name" value="" />

to

<input type="text" name="name" value="My Name" />

How do I get the country multiple select box to highlight or pre select the option values that match the data held in the submission country field?

Hope this makes sense

thanks

Mark

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by pritaeas
0

If you generate this select box in code, then just add the selected attribute to the values from the database.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.