473,667 Members | 2,642 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing background color of the options in a drop down menu using JS

5 New Member
Here is what I am trying to do. I am using a JS button to create a new row in a table. In the new row I have two text boxes and a drop down list. I am wanting to set the background color of each of my options in the drop list.

Here is the section of the JS code that I create the drop down list.
Expand|Select|Wrap|Line Numbers
  1. //cell 1
  2. var cell1 = row.insertCell(1);
  3. var el = document.createElement("select");
  4. el.name = 'Status[]' // sets the name of the row to status
  5. el.options[0] = new Option("Available");
  6. el.options[1] = new Option("Busy");
  7.  
  8. cell1.appendChild(el);
In my HTML code I can get the first drop down list to have color but for any additional rows the color is not set. Any thoughts or suggestions would be greatly appreciated. I have been hitting my head against a wall for two weeks now
May 30 '12 #1
3 3580
Dormilich
8,658 Recognized Expert Moderator Expert
how do you set the color for the first dropdown list?
May 30 '12 #2
IndyNS
5 New Member
Expand|Select|Wrap|Line Numbers
  1. <style>
  2. option.Avaliable {background-color:green} 
  3. option.Busy {background-color:red}
  4. </style>
  5.  
then in the body
Expand|Select|Wrap|Line Numbers
  1. <option value="0" class="Avaliable">Avaliable</option>
  2. <option value="1" class="Busy">Busy</option>
  3.  
May 31 '12 #3
Dormilich
8,658 Recognized Expert Moderator Expert
then you only need to give your new options the appropriate class names as well.
May 31 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

10
3467
by: Haines Brown | last post by:
I've implemented the horizontal drop down menu discussed recently in this newsgroup, and it works nicely under Galeon and Mozilla, but not IE 5.0. Here are the problems: Under IE 5.0, the there is no drop down menu functionality at all. I wanted to implement an alternative stylesheet for IE, but my link to it is apparently broken. What is wrong with my link? I'd
2
2567
by: hemanth.singamsetty | last post by:
Hello there, I've a drop down menu (created using CSS & Javascript -- see code below). My problem is, whenever I click a link on the menu the new page replaces the current page (and the menu disappears). Is there a way, I can keep the menu always on top. ( A good example of what I'm looking for is similar to the menu bar in http://www.milonic.com/ ).
2
1686
by: Logan | last post by:
I'd like to create a dropdown menu (with submenus) using vb.net. Does anyone have any idea how i could go abouts achieving this? tks in advance.
4
2409
by: Amil | last post by:
Does anyone have a recommendation on an AWESOME (free) horizontal drop-down menu using DTHML? I'm not using VS 2005 yet. Thanks. Amil
2
3006
by: bissatch | last post by:
Hi, I have created a drop down menu using nested lists and CSS :hover. I have uploaded it so that people can have a look: http://www.martynbissett.co.uk/testing/dd05.html In FF, it works fine but in IE the boxes are hidden behing other list elements. I have tried setting z-index but apart from that, I dont know how I might fix it. Any ideas?
4
9287
by: TycoonUK | last post by:
Hi, As I do not have IE7 on my computer, I was wondering if there is a fault in my CSS Menu when using IE7. Please can someone look at my site - http://www.worldofmonopoly.co.uk and tell me if it works, and if it does not, tell me why it does not work. Thanks.
6
1984
by: patelxxx | last post by:
How do I create a new folder in a 'Drop Down Menu' using JavaScript? I have not tried anything yet, so all idea's are welcomed.
1
3035
by: daydreaming | last post by:
Hi All, I would like to know is there any way to set the color of the button in drop-down menu. Below is the sample HTML object (select) that I would like to set its button color. <html> <select style="border-bottom:1px solid #dadada"> <option>Menu Item 01</option>
5
3516
ddtpmyra
by: ddtpmyra | last post by:
I cannot select the distinct records but Im pretty sure im connected to the database. Please tell me what's wrong with this? and why I cannot see the query result? thanks! echo "Status:"; $res=mssql_query("SELECT distinct(contactmethod) FROM users with(nolock)"); if(mssql_num_rows($res)==0){ echo "there is no data in table.."; } else {
0
2197
by: buzzard724 | last post by:
Ul li drop down menu works in FF not quite in IE Thank you for looking at this. The page is generated dynamically by php, js and jquery. The drop down menu ul- reports-li - works fine in FF. In IE7 the menu displays and if I am very very careful with how I move the mouse I can sometimes manage to catch the submenu - particularly the first time the page is displayed. Usually the menu disappears before I can mouse over it. I guess this is...
0
8459
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8889
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8790
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8570
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8650
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7391
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2781
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1779
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.