Jump to content

Multiple Selectbox "SELECT" Attribute?


jamesjmann

Recommended Posts

I know this is probably going to sound like a stupid question, but I have a multiple select box with this code:

 

<select MULTIPLE>

</select>

 

And a foreach statement that dynamically generates <option>'s.

 

I want one option to be automatically selected when the user clicks the page, depending on a certain $_GET variable in the query string.

 

I tried:

 

<option SELECTED>

 

Like you would a normal <select> and this didn't work. Anyone know if this is even possible?

 

Note: I tried googling it, but google turned up nothing. Someone help. I'm a newb at multiple selects lol.

Link to comment
https://forums.phpfreaks.com/topic/254064-multiple-selectbox-select-attribute/
Share on other sites

Following works for me -

<form action="formaction.php">
<select multiple="multiple" name="cars[]">
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value="opel" selected="selected">Opel</option>
  <option value="audi">Audi</option>
</select>
<input type="submit" />
</form>

 

Are you sure you output the correct syntax in your actual form?

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.