473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

retaining value in listbox array

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??????

Jan 12 '07 #1
2 6287
"php_Boi" <ti******@gmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
<select name="title[]" //note title[] = an array
of titles within the form
<option value="1"<?php if ($_POST['title'] == '1') { echo
If you make an array of it, then shouldn't you be looking at the first
element of the array? $_POST['title'][0]

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Jan 12 '07 #2

Kimmo Laine wrote:
"php_Boi" <ti******@gmail.comwrote in message
news:11**********************@v45g2000cwv.googlegr oups.com...
<select name="title[]" //note title[] = an array
of titles within the form
<option value="1"<?php if ($_POST['title'] == '1') { echo

If you make an array of it, then shouldn't you be looking at the first
element of the array? $_POST['title'][0]

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Yeah that is what i thought too, with a similar syntax. what i mean is
because it can grow and shrink dynamically like there can be 4
responses or one i set a counter like $count and then tried
<option value="1"<?php if $_POST['title'][$count] == '1') { echo
'selected="selected"'; } ?>></option>
but i made a trivial error. the variable i used $count was not in the
scope of these form elements. so i managed to resolve it by using the
counter that "grew" and "Shrunk" the form. if anyone wants to see how
it works email me and i'l send u a copy its pretty nifty.

Thanks Kimmo Laine at least after banging my head against a wall i saw
i wasnt nuts and was on the right track. just needed to pay more
attention to variable scope :)

Jan 12 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cgplays.com | last post by:
I have a select-pulldown at http://computergroupplays.com/fb-pres2.asp that changes the 3rd pulldown (Dbase) depending on what the user enters in the 2nd (Wk). My associate wants the values inside...
19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
10
by: Ben | last post by:
Hi Im trying to get the value from a listbox, i have the below code to get the text: txtEntity.Text = ListBox1.Text But do not seem to be able to retrieve the data that i set as the value...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
6
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am...
1
by: bbasberg | last post by:
Hello, I am wondering how to "carry over" a value from a listbox on one worksheet in the workbook to a cell in another worksheet in the same workbook. For example, to just copy over a value...
0
by: crespo | last post by:
hi,everyone. I have a question about using listbox in a customized user control.I use a listbox directly in a asp.net page and it works very well,but when I use the same code in a user...
2
by: Tim Royal | last post by:
I'm using a GridView inside a Wizard Control with a textbox and two listboxes in the footer. I populate these listboxes from the database if the page isn't on postback (and the textbox is left...
3
by: Sweetiecakes | last post by:
Hi I have an string array containing file paths. I have added them to a ListBox with AddRange(); When I delete an item from the ListBox, how can I delete the same item from the original...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.