hey 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:
This ain't working though. This is my button:
How can I do this?
Thanks,
Amit
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
;
}
}
<
asp:Button
ID
=
"btnSearch"
runat
=
"server"
Style
=
"float: left; color: black; font-weight: bold"
Text
=
"Search"
OnClick
=
"btnSearch_Click"
OnClientClick
=
"javascript: return filterSearch();"
/>
Thanks,
Amit
6 Answers, 1 is accepted
0
Accepted
Shinu
Top achievements
Rank 2
answered on 09 Nov 2010, 02:03 PM
Hello Amit,
Here is code snippet I tried for my application for a similar scenario. I hope this would help you also.
Here is the code.
Javascript:
Shinu.
Here is code snippet I tried for my application for a similar scenario. I hope this would help you also.
Here is the code.
Javascript:
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
;
}
}
Shinu.
0
Amit
Top achievements
Rank 1
answered on 10 Nov 2010, 05:23 AM
Thanks Shinu,that was perfect...
0
David
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 03 May 2018, 03:52 PM
To resurrect old thread:
if (combo.get_selectedIndex() == null)
gives me an error in Firefox. I tried other solutions with no luck
0
Hi David,
Regards,
Marin Bratanov
Progress Telerik
What is the error and its stack trace? I am attaching here a video of my test and this seems to work as expected. What am I missing from your setup and attempts? Can you paste here the combo box markup so I can see how you are using it?
Regards,
Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which
deliver the business app essential building blocks - a grid component,
data visualization (charts) and form elements.
0
David
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 08 May 2018, 12:37 PM
Hi Marin,
Embarrassingly, it works fine now, not sure what happened, likely my bad.
Sorry to resurrect the issue.
Thank you
David
0