remove an item in drop down list after the form is submitted

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
mathieu
Forum Newbie
Posts: 2
Joined: Tue Aug 24, 2010 8:50 pm

remove an item in drop down list after the form is submitted

Post by mathieu »

hey
I am using a php drop down list that is populated from a mysql database. The list is on a form and i need to be able remove an item from the list once it has been selected and submitted in the form. Once the item has beeen selected and submitted in the form it has to be deleted from the list.
Any ways i can do this?

thanks
phpaverage
Forum Newbie
Posts: 5
Joined: Thu Sep 30, 2010 3:55 am

Re: remove an item in drop down list after the form is submi

Post by phpaverage »

google is your best friend or you pay me and il help you :twisted:
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: remove an item in drop down list after the form is submi

Post by DigitalMind »

It depends on what exactly you want to do. If you want to remove the items just for the current session use something like $_SESSION['deleted_items][] and don't output the items which are in that array.
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: remove an item in drop down list after the form is submi

Post by DigitalMind »

phpaverage wrote:google is your best friend or you pay me and il help you :twisted:
Would you like to have a cup of poison?
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: remove an item in drop down list after the form is submi

Post by twinedev »

If you have the drop down list on a form that does an AJAX call (ie, the form stays on the page when you submit it), you can use the following:

(assuming here that the function was passed this as a parameter named elem, otherwise you will need to set elem to be the select element first)

Code: Select all

elem.options[elem.selectedIndex] = null; 
-Greg

PS. Digitalmind, I was very tempted to go copy his reply to his own questions here LOL
Post Reply