I have a popup select box in a form in my jQuery Mobile application.
<div data-role='fieldcontain'>
<label for='fruits' class='select'>Favorite Fruits</label>
<select name='fruits' id='fruits' multiple='multiple' data-native-menu='false'>
<option>Favorite Fruits</option>
<option value='1' checked='checked'>Apple</option>
<option value='2' checked='checked'>Banana</option>
<option value='3' checked='checked'>Cherry</option>
</select>
</div>
The value attributes of the option elements are equal to the database IDs of the fruits. After the form is submitted, I try to access the array of elements selected with
$fruits = $_POST['fruits'];
However, var_dump($fruits)
issues an error noting that $fruits is not defined. Why?
After some tinkering I think you have three issues:
name="fruits[]
checked="checked"
should be selected="selected"
value=""
checked='checked'
is not working in that it is not getting those options selected by default. I'm working that out too - John Hoffman 2012-04-04 04:11