You are here: retaining value in listbox array « PHP Programming Language « IT news, forums, messages
retaining value in listbox array

Posted by php_Boi on 01/12/07 07:18

i have designed an application that is a dynamic submission form. i
have text fields and listboxes. now i am able to retain the values of
the listboxes when i populate the listbox "manually"(single listbox)
like this...

<select name="title">
<option value="1"<?php if ($_POST['title'] == '1') { echo
'selected="selected"'; } ?>></option>
<option value="Mr"<?php if ($_POST['title'] == 'Mr') { echo
'selected="selected"'; } ?>>Mr</option>
<option value="Mrs"<?php if ($_POST['title'] == 'Mrs') { echo
'selected="selected"'; } ?>>Mrs</option>
<option value="Mstr"<?php if ($_POST['title'] == 'Ms') { echo
'selected="selected"'; } ?>>Ms</option>
</select>

Now this works flawlessly for example if the firstname text box is left
blank and the user clicks "send" then validation occurs and the value
in the "title" listbox is maintained and user is prompted to fix the
error. However this does not work when i use a listbox that is
dynamically generated in an array.

<select name="title[]"> //note title[] = an array
of titles within the form
<option value="1"<?php if ($_POST['title'] == '1') { echo
'selected="selected"'; } ?>></option>
<option value="Mr"<?php if ($_POST['title'] == 'Mr') { echo
'selected="selected"'; } ?>>Mr</option>
<option value="Mrs"<?php if ($_POST['title'] == 'Mrs') { echo
'selected="selected"'; } ?>>Mrs</option>
<option value="Mstr"<?php if ($_POST['title'] == 'Ms') { echo
'selected="selected"'; } ?>>Ms</option>
</select>

But my text boxes work(retain value on POST in the case there is
invalid input on the form)
<input name="fname[]" type="text" value="<?php echo $firstname;?>"/>

i have tried a couple of scenarios and in my debugging i see that if i
chose the "Mr" option and 'echo' to see if it is POST'ed, it is.
However when the form reloads it reverts to the default empty value of
the listbox?????

thought maybe something like
//code above
<option value="Mr"<?php if ($_POST['title'][$count] == '1') { echo
'selected="selected"'; } ?>></option>
//code below
But nothing...So how to retain the value of the listbox??????

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация