By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,053 Members | 1,192 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,053 IT Pros & Developers. It's quick & easy.

Problem with receving selection list values

P: n/a
Ok the problem is this, when i try to receve the values from a form with the
selection list below:

<select name="jogos" size="5" multiple id="jogos">
<option value="1">Battlefield 1942</option>
<option value="2">Call of Duty</option>
</select>

The problem is that the variable $_POST['jogos'] only have the last option,
for example if i select Battlefield 1942 (value 1) and Call of Duty (value
2) it only have the value 2.

What i'd like to know is how to get all the values selected from the select
list.

Thx in advance,
João Proença
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> <select name="jogos" size="5" multiple id="jogos">
<option value="1">Battlefield 1942</option>
<option value="2">Call of Duty</option>
</select> The problem is that the variable $_POST['jogos'] only have the last option, for example if i select Battlefield 1942 (value 1) and Call of Duty (value
2) it only have the value 2.
What i'd like to know is how to get all the values selected from the select list.


You need to name select-element like name="jogos[]". And result is then IN
PHP-ARRAY called jogos(not jogos[] ). Programs like Frontpage can complain
about naming elements in this manner, but ignore it. This is only and right
way with php.

BTW, remember also to have something selected as default. I have impression
that different browsers may behave differently if you dont have default
selection and user doesn't choose any option. With database driven systems
<option selected value="0">Choose your jogos</option> is usually good,
because id-values that come fron database are positive integers, not zero.
Or of course value="false" or something else special enought works fine too.

perttu p, finland


Jul 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.