473,503 Members | 12,159 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Determine contents of listbox

How can I determine the values of a listbox, both unselected or
selected after submitting the form:

Code:

<select name="sel1" size="10" multiple="multiple">
<? PHP code populates listbox ?>
</select>
Do I have to use Javascript to determine the contents, like in the
pseudo code Javscript below. But how would you pass the Javascript
return value to PHP?

Code:

function listBoxContents(sel1)
{
var selLength1 = sel1.length;
var valuesPresent1 = new Array(sel1.length-1);
var i;
for(i=0; i<=selLength1-1; i++)
{
valuesPresent1[i]=sel1.options[i].valueOf();
}

return valuesPresent1;
}

May 3 '07 #1
2 4267
On May 3, 5:45 am, tks...@gmail.com wrote:
How can I determine the values of a listbox, both unselected or
selected after submitting the form:

Code:

<select name="sel1" size="10" multiple="multiple">
<? PHP code populates listbox ?>
</select>

Do I have to use Javascript to determine the contents, like in the
pseudo code Javscript below. But how would you pass the Javascript
return value to PHP?

Code:

function listBoxContents(sel1)
{
var selLength1 = sel1.length;
var valuesPresent1 = new Array(sel1.length-1);
var i;
for(i=0; i<=selLength1-1; i++)
{
valuesPresent1[i]=sel1.options[i].valueOf();
}

return valuesPresent1;

}
if you form uses POST just use
<?php
print_r($_POST['sel1'])
?>
to see the array you get when you select certain options in the form
assuming yur markup is correct you will get values. your php code for
the options in the drop down might have the values for each option
like so, assuming a loop of some kind:
$dropdown = '';
$dropdown .= '<option value="' . $value[$i] .'">'.$value[$i].'</
option>'."\n";

May 3 '07 #2
On May 3, 11:45 am, tks...@gmail.com wrote:
How can I determine the values of a listbox, both unselected or
selected after submitting the form:

Code:

<select name="sel1" size="10" multiple="multiple">
<? PHP code populates listbox ?>
</select>
Add hidden elements to your form, set the values same as value of your
options.
Untested code:

<select name="sel1[]" size="10" multiple="multiple">
<?php foreach ($arr as $k=>$v) { ?>
<option value="<?php echo $k; ?>"><?php echo $v; ?></option>
<?php } ?>
</select>

<?php foreach ($arr as $k=>$v) { ?>
<input type=hidden name="sel1all[]" value="<?php echo $k; ?>">
<?php } ?>

HTH.

May 3 '07 #3

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

Similar topics

6
1596
by: Christina | last post by:
I want to read a classic HTML Form using the ASP Request object on the server. This is a common approach. But how can I read all the contents of a listbox (the <select> tag)? Best regards,...
13
7622
by: Gittyup | last post by:
Help please, We have a form, based on a query, that contains a listbox. The contents of the listbox are based on the results of the query. When the form is opened, the user selects an item...
1
6064
by: Ray Mitchell | last post by:
Hello, I have a simple application in which I am using a ListBox to display text strings for logging purposes. When the text area becomes full the new lines are added to the end and the...
6
1765
by: SStory | last post by:
Can anyone tell me what algorithm I should use to determine how many tabs to add to a string. I have two strings. I want to add them to a listbox concatenated but with a tab between them. ...
2
1493
by: Joe Fallon | last post by:
I need to save the contents of a listbox in a serializable object. I not only need the values but the index positions as well. For example, a listbox with 3 entries may look like this: Index ...
9
18915
by: Paul H | last post by:
I have developed several databases in Access. I know VBA. I am making the jump to VB and am currently using Visual basic 2005 Express. Can anyone give me a snippet that will show me how to list...
0
1177
devonknows
by: devonknows | last post by:
Hey everyone, i was wondering is there anyway that you can print the contents of a list box only, i have a large listbox that has over 300 entries inside it. so dont really want to have to make the...
1
1292
by: servernet1997 | last post by:
I have a gridview with 4 columns. Two of the columns are read-only and two are editable. The two editable columns are listboxes leveraging an ObjectDataSource. The first listbox is populated from a...
3
1366
by: tks423 | last post by:
Hi, I was wondering if this is correct code for determine the contents of a listbox. I'm particularly interested to know if the sel1.options.valueOf() call will tell me the value of the item as...
0
7193
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6975
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4992
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3148
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
371
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.