基于一个下拉选择选项的背景色显示警报 [英] Display alert based on the background color of a drop down select option

查看:134
本文介绍了基于一个下拉选择选项的背景色显示警报的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个有一个下拉列表,它是由数据库填充,列表中的某些选项根据他们是否已经禁用或不具有不同的背景颜色。

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.

我想运行它运行的onChange如果用户试图选择具有红色背景色列表中的用户显示一条警告VB脚本。

I would like to run a VB script which runs onChange which displays an alert if the user tries to select a user from the list which has a red background colour.

例如:

Jim
Bob   ----> Red Background (Highlighted Red)
Dave
Tom

这时如果用户试图选择鲍勃那么它会弹出一个警告,然后集中选择返回NULL。

then if the user tries to select Bob then it will bring up an alert and then focus the select back to NULL.

Sub TestSub()
            frmCol = document.getElementById("frmNew").style.backgroundColor
            if frmCol = "Red" Then
            msgbox "This user is banned, please select another user!"
            End If
        End Sub

希望这是有道理的!感谢您的帮助,非常AP preciated。问是否需要更多的细节!

Hopefully that makes sense! Thank you for any help, very much appreciated. Ask if more details are needed!

推荐答案

这样的事情应该做你想要什么:

Something like this should do what you want:

For Each opt In document.getElementById("frmNew").options
  If opt.selected And opt.style.backgroundColor = "red" Then
    MsgBox "This user is banned."
  End If
Next

不过,正如@DanielCook说,刚检查,对禁止的用户列表中的实际名称将是一个更好的办法,因为应用程序逻辑是少笼罩这种方式:

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
...

For Each opt In document.getElementById("frmNew").options
  If opt.selected And bannedUser.Exists(opt.text) Then
    MsgBox "This user is banned."
  End If
Next

这篇关于基于一个下拉选择选项的背景色显示警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆