Multiple selection html dropdownlist

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lokesh_kumar_s
Forum Commoner
Posts: 48
Joined: Mon Apr 13, 2009 5:39 am
Contact:

Multiple selection html dropdownlist

Post 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
maneetpuri
Forum Commoner
Posts: 60
Joined: Tue Oct 07, 2008 6:32 am

Re: Multiple selection html dropdownlist

Post 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
phpneeds
Forum Newbie
Posts: 2
Joined: Tue Jul 07, 2009 6:19 am

Re: Multiple selection html dropdownlist

Post 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']);
Post Reply