Skip to content Skip to sidebar Skip to footer

Display Alert Based On The Background Color Of A Drop Down Select Option

A have a drop down list which is being populated by a database, certain options in the list have a different background colour according to whether they have been banned or not. I

Solution 1:

Something like this should do what you want:

ForEach opt In document.getElementById("frmNew").options
  If opt.selected And opt.style.backgroundColor = "red"Then
    MsgBox "This user is banned."EndIfNext

However, as @DanielCook said, just checking the actual name against a list of banned users would be a better approach, because the application logic is less shrouded that way:

Set bannedUsers = CreateObject("Scripting.Dictionary")
bannedUsers.Add "johnsmith", True
bannedUsers.Add "cmanson", True
...

ForEach opt In document.getElementById("frmNew").options
  If opt.selected And bannedUser.Exists(opt.text) Then
    MsgBox "This user is banned."EndIfNext

Post a Comment for "Display Alert Based On The Background Color Of A Drop Down Select Option"