如何获取组合框选择的项目与JavaScript为空? [英] how to get if combobox selected item is null with javascript?

查看:51
本文介绍了如何获取组合框选择的项目与JavaScript为空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想验证一个按钮,以便如果组合框选择的项目计数等于零,那么单击按钮将在客户端显示警报.我正在这样做:

Hi everyone,

I want to validate a button such that if combobox selected items count is equal to zero then button click will show an alert on client side. I am doing this:

function filterSearch()
{
  var combo = $find(''<%=RadComboBox1.ClientID %>'');
  var textbox = document.getElementById("txtSearch");
  var selectedItemsCount = combo.get_selectedItems().length;
  if (selectedItemsCount == 0) 
  {
    alert("You must select a category before processing search!");
    return false;
  }
}


不过这没有用.这是我的按钮:


This ain''t working though. This is my button:

<asp:Button ID="btnSearch" runat="server" Style="float: left; color: black; font-weight: bold" Text="Search" OnClick="btnSearch_Click" OnClientClick="javascript: return filterSearch();" />


我该怎么办?

谢谢,
Amit


How can I do this?

Thanks,
Amit

推荐答案

find(''<%= RadComboBox1.ClientID%>''); var textbox = document.getElementById("txtSearch"); var selectedItemsCount = combo.get_selectedItems().length; 如果(selectedItemsCount == 0) { alert(必须先选择类别再进行搜索!"); 返回false; } }
find(''<%=RadComboBox1.ClientID %>''); var textbox = document.getElementById("txtSearch"); var selectedItemsCount = combo.get_selectedItems().length; if (selectedItemsCount == 0) { alert("You must select a category before processing search!"); return false; } }


不过这没有用.这是我的按钮:


This ain''t working though. This is my button:

<asp:Button ID="btnSearch" runat="server" Style="float: left; color: black; font-weight: bold" Text="Search" OnClick="btnSearch_Click" OnClientClick="javascript: return filterSearch();" />


我该怎么办?

谢谢,
Amit


How can I do this?

Thanks,
Amit


这是我现在正在使用的代码,它的工作正常...

Here is the code i am using now,and its working fine...

function filterSearch()
{
       var combo =


find(' var 文本框= document.getElementById(" span>); 如果(combo.get_selectedIndex()== ) { alert(" ); 返回 ; } }
find('<%=RadComboBox1.ClientID %>'); var textbox = document.getElementById("txtSearch"); if (combo.get_selectedIndex() == null) { alert("You must select a category before processing search!!"); return false; } }



并且按钮与以前相同-



and for button same as before--

<asp:Button ID="btnSearch" runat="server" Style="float: left; color: black; font-weight: bold" Text="Search" OnClick="btnSearch_Click" OnClientClick="javascript: return filterSearch();" />


这篇关于如何获取组合框选择的项目与JavaScript为空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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