Move this topic
select checkbox with this name
in Getting Started
•
13 years ago
The name of the checkbox is ctl00$cphMainContent$702$cbSelect
please note there are more then one checkbox but want to select them all
I am having a hard time finding the right selecttor so far i tryed this
var CheckboxList = $('input:checkbox'[name*='cbSelect'])
can any one help me ?
please note there are more then one checkbox but want to select them all
I am having a hard time finding the right selecttor so far i tryed this
var CheckboxList = $('input:checkbox'[name*='cbSelect'])
can any one help me ?
1
Replies(3)
Re: select checkbox with this name
13 years ago
you can use "class"
<input type="checkbox" name="cbSelect1" class="check">
<input type="checkbox" name="cbSelect2" class="check">
<input type="checkbox" name="cbSelect3" class="check">
<input type="checkbox" name="cbSelect4" class="check">
<script>
$(".check").attr('checked',true);
})
</script>
<input type="checkbox" name="cbSelect1" class="check">
<input type="checkbox" name="cbSelect2" class="check">
<input type="checkbox" name="cbSelect3" class="check">
<input type="checkbox" name="cbSelect4" class="check">
<script>
$(".check").attr('checked',true);
})
</script>
Leave a comment on rupaknitd's reply
Re: select checkbox with this name
13 years ago
This is my asp button.
<asp:Button ID="btnEdit" Width="65px" runat="server" Text="Edit"
onclick="btnEdit_Click" OnClientClick="Check();" />
<script type="text/javascript">
function Check() {
var CheckedTrue = 0;
var CheckboxList = $(".check").attr('cb', true);
for(var i = 0; CheckboxList.length > i; i++)
{
if(CheckboxList.get(i).checked == true)
{
CheckedTrue++
}
}
if (CheckedTrue < 2) {
alert("Works");
}
else {
alert('You can only selected control at a time');
return false;
}
}
</script>
And this is my chechbox and I have many of them.
<asp:CheckBox ID="cbSelect" runat="server" AutoPostBack="true"
oncheckedchanged="cbSelect_CheckedChanged" CssClass="cb" />
at run time the Chechbox looks like this
<input type="checkbox" onclick="javascript:setTimeout('__doPostBack(\'ctl00$cphMainContent$701$cbSelect\',\'\')', 0)" checked="checked" name="ctl00$cphMainContent$701$cbSelect" id="ctl00_cphMainContent_701_cbSelect">
var CheckboxList = $(".check").attr('cb', true); don't seem to work
I have alos tryied this selector var CheckboxList = $([type=checkbox : name*='cbSelect'])
but that didn't work either
How do I select the checkboxes with ID cbSelect and not others on my page?
Thanks in advance!
Leave a comment on entvex's reply
回复: select checkbox with this name
13 years ago
the asp.net server control have a ClientID property, you can use it to get the real id
Leave a comment on xiyunma's reply
Re: select checkbox with this name
13 years ago
<script type="text/javascript">
function Check() {
var CheckedTrue = 0;
// var CheckboxList = $(input[name*='cbSelect'])
var CheckboxList = $('input:checkbox')
for(var i = 0; CheckboxList.length > i; i++)
{
if (CheckboxList.get(i).name.indexOf("cbSelect", 0) != -1) {
if (CheckboxList.get(i).checked == true) {
CheckedTrue++;
}
}
}
if (CheckedTrue < 2) {
//Do norting
}
else {
alert('You can only selected control at a time!');
return false;
}
}
</script>
this works !
function Check() {
var CheckedTrue = 0;
// var CheckboxList = $(input[name*='cbSelect'])
var CheckboxList = $('input:checkbox')
for(var i = 0; CheckboxList.length > i; i++)
{
if (CheckboxList.get(i).name.indexOf("cbSelect", 0) != -1) {
if (CheckboxList.get(i).checked == true) {
CheckedTrue++;
}
}
}
if (CheckedTrue < 2) {
//Do norting
}
else {
alert('You can only selected control at a time!');
return false;
}
}
</script>
this works !
Leave a comment on entvex's reply
Change topic type
Link this topic
Provide the permalink of a topic that is related to this topic
Reply to entvex's question
Statistics
- 3 Replies
- 23335 Views
- 0 Followers