What I am trying to do is:
if one or more checkboxes are selected, display cboResearch and btnResearch
The tricky part to me is that the check box names are based on a loop. So, to summarize, I’d like to have that:
- If one or more boxes are checked, display dropdown menu and button
- If all check boxes are unchecked, hide dropdown menu and button
I have provided everything but the recordset code below – hopefully it will suffice for the crux of the question.
<head>
<!--Jquery drop down menu add-on-->
<script type="text/javascript" src="../js/jquery-1.6.1.min.js"></script>
<script type="text/javascript" src="../js/jquery.dd.js"></script>
<script language="javascript">
$(document).ready(
function() {
//JQuery code for drop-down menus
try {
oHandler = $(".mydds").msDropDown().data("dd");
$("#ver").html($.msDropDown.version);
} catch (e) {
alert("Error: " + e.message);
}
});
//Function to select all check boxes.
$(function() {
$('.checkall').click(function() {
$(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);
});
});
</script>
</head>
<body>
<form>
<fieldset>
<p>Select All
<input type="checkbox" name="cbSelectAll" id="cbSelectAll" class="checkall">
</p>
<% Dim iX iX=0 Do While Not RS.EOF iX=i X + 1 %>
<p>
<input type="checkbox" name="cbSelection<%=iX%>" id="cbSelection<%=iX%>"
/>
</p>
<% RS.MoveNext Loop %>
<p>
<select name="cboResearch" id="cboResearch">
<option value="1">option1</option>
<option value="2">option2</option>
</select>
</p>
<p>
<input name="btnResearch" type="button" class="button" value="Research" />
</p>
</fieldset>
</form>
</body>
Thank you for updating your code, it makes a lot clearer now what is repeated and what is not.
For selecting all checkboxes I’m using
^=which is jQuery’s Attribute Starts With SelectorYou can bind to the change event of the checkboxes inspecting their state and based on that either hide or show the required elements.
You also want to inspect that state and react to it on page load as well as when chack-all is checked/unchecked. I added comments throughout the script for you to see what’s what.
DEMO – show dropdown/button on check, else hide
The DEMO uses the following script:
The HTML from the DEMO