Dynamically add/remove a SELECT item

Javascript coding ..

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 7
Joined: Fri Mar 16, 2012 9:20 am

Dynamically add/remove a SELECT item

Postby AZDJedi » Sat Apr 14, 2012 10:37 am


I'm having trouble getting this code working 100%. Any help would be great!

Basically, I want the dropdown to display "Select from the list", but as soon as it gets focus I want that item to be deleted. When they move off the dropdown I want that item to be re-added (assuming they have selected at least item 2 (item 1 is "add new"). Alternatively, if you can suggest a cleaner way to give them an instruction without having a label...

This is what I have so far, but it keeps removing items 0 AND 1 for some reason :S. The Action variable is passed from onblue and onfocus.

Code: Select all

 if (Action==1) {
      if (cbo.options[cbo.selectedIndex].text=="Select from the list")
   }else if (Action==0) {
      if (cbo.value==0) {
         cbo.options[0] = new Option('Select from the list?', -1);

Return to “JavaScript”

Who is online

Users browsing this forum: No registered users and 2 guests