Page 1 of 1

Multiple selection html dropdownlist

Posted: Mon Jul 06, 2009 3:05 am
by lokesh_kumar_s
hi i want to use html drop down list with multiple selection option

Code: Select all

 
<form name="myform">
 <select multiple="multiple" name="DrpEmployee" style="width: 173px">
 <option>1</option>
 <option>2</option>
 <option>3</option>
 <option>4</option>
 <option>5</option>
 <option>6</option>
 <option>7</option>
 </select>
  
  <input type="submit" name="submit" value="submit" onclick="return Validate(this.form)" />
  </form>
 
 
i want to access this DrpEmployee drop down list in javascript for validations some people said me to use the following code to access the dropdown list

Code: Select all

 
function Validate(frm)
{
 var count = 0
 for (var i=0, len=frm.DrpEmployee.options.length; i<len; i++)
 {
        if (frm.DrpEmployee.options[i].selected)
        count++;
 }
 
 
here count is nothing but number of selected items.

the problem is i also want to access the DrpEmployee in php . can you specify the code to access the DrpEmployee selected items

Re: Multiple selection html dropdownlist

Posted: Tue Jul 07, 2009 6:16 am
by maneetpuri
Hi,

You can access the dropdown in PHP using the $_GET or $_POST depending upon the method you have used in form, the value you will get will be an array of multiple selections the user selected.

Hope this helps.

Cheers,

~Maneet

Re: Multiple selection html dropdownlist

Posted: Tue Jul 07, 2009 6:44 am
by phpneeds
This one gives u the "Array".

echo $_REQUEST['DrpEmployee'];

U can see all the values using the following code.

print_r($_REQUEST['DrpEmployee']);