Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();" />

How can I do this?

Thanks,
Amit
Posted
Updated 8-Nov-10 20:00pm
v3

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

C#
function filterSearch()
{
       var combo = $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();" />
 
Share this answer
 
Hi Amit,
Please look into this article.
http://shivasoft.in/view_tutorial.php?id=96[^]
I hope this would help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900