Displaying of dropdown list in php

Hi everybody,
I need some help and suggestions. I am trying to display all items of dropdown list where selected or unselected.
Is that possible in PHP or not?
If possible, help me to solve it. Or it is possible to display only selected items.
I have added items to dropdown list programmitically.

Thanks in Advance.

here is code i have done so far

[COLOR=“Blue”]<HTML>
<HEAD>
<TITLE>untiled</TITLE>
<script>
//add selected size to dropdown
function AddSize()
{
// Create an Option object

var opt = document.createElement("option");

// Add an Option object to Drop Down/List Box
document.getElementById("ddlselected").options.add(opt);

// Assign text and value to Option object
var ddlist=window.document.getElementById('ddlsize');
var ddvalue=ddlist.options[ddlist.selectedIndex].value;
opt.text = ddvalue;
opt.value = ddvalue;

}

//add selected size to dropdown
function AddBinding()
{
// Create an Option object

var opt = document.createElement("option");

// Add an Option object to Drop Down/List Box
document.getElementById("ddlselectedbingdings").options.add(opt);

// Assign text and value to Option object
var ddlist=window.document.getElementById('ddlbindings');
var ddvalue=ddlist.options[ddlist.selectedIndex].value;
opt.text = ddvalue;
opt.value = ddvalue;
//opt.selected=true;

}

//remove selected item from dropdown
function removeOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i–)
{
if(selectbox.options[i].selected)
selectbox.remove(i);
}
}

</script>

</HEAD>
<BODY>
<form name=“isertp” id =“isertp” action=“” method=“post” enctype=“multipart/form-data”>

&lt;TABLE id="dataTable" border="0"&gt;

<tr>
<td>Select Sizes : </td>
<td>
<select name=“ddlsize” size=“1” id=“ddlsize”>

      &lt;option value="test"&gt;test&lt;/option&gt; 
       &lt;option value="test1"&gt;test1&lt;/option&gt;
        &lt;option value="test2"&gt;test2&lt;/option&gt;
         &lt;option value="test3"&gt;test3&lt;/option&gt;
          &lt;option value="test4"&gt;test4&lt;/option&gt;
           &lt;option value="test5"&gt;test5&lt;/option&gt;
    &lt;/select&gt;      &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;&nbsp;&lt;/td&gt;
  &lt;td&gt;
  &lt;input type="button" name="btnsize" id="btnsize" value="Add More size" onClick="AddSize()"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;Selected Sizes : &lt;/td&gt;
  &lt;td&gt;
    &lt;select name="ddlselected" size="5" multiple id="ddlselected"&gt;
    &lt;/select&gt;       
    &lt;input type="button" name="remove" id="remove" value="Remove Selected" onClick="removeOptions(ddlselected)"&gt;     &lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
  &lt;td&gt;&nbsp;&lt;/td&gt;
  &lt;td&gt;
  &lt;input type="submit" name="button" id="button" value="Submit"&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;

</TABLE>
</form>
</BODY>
</HTML>
[/COLOR]

now what i want to do that i want display all items of ddlselected dropdown list

post the code you have so far and we can try to help you.

I’m not sure what you want to display because your ddlselected select list is currently empty and doesn’t have any options

 
<select name="ddlselected" size="5" multiple id="ddlselected">
</select>

but in any case, when you put some options in the <select> and set multiple=“multiple” you must add to the name of the <select> so that an array of the selected values from the <select> will be sent to the php script.

for example

 
<select name="selMySelectList[]" multiple="multiple">
     <option value='a'>A</option>
     <option value='a'>B</option>
     <option value='a'>C</option>
     <option value='a'>D</option>
</select>

will send an array of values from the selected options to
$_POST[‘selMySelectList’] in the php script.

you can then process $_POST[‘selMySelectList’] just like any other php array.

Hi Kalon,
its not working, it will display only selected items. instead i want to display or get all items wheather selected or not.
If it is not possible, is there any way which will give same output.

when you submit a form, only the selected values will be sent.

if you want the values of all the options, whether selected or not, you could use javascript to get the values of all the options and store them in a hidden input in the form which will then be sent to the php script along with the other form data when the form is submitted.