Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > ASP Pro Code Clinic
|
ASP Pro Code Clinic As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Pro Code Clinic section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 14th, 2004, 02:00 PM
Authorized User
 
Join Date: Jan 2004
Posts: 30
Thanks: 1
Thanked 0 Times in 0 Posts
Default Checking/Unchecking while Disabling/Enabling Check

I am updating a page which has a table with four checkboxes that receives data from a db. The results are sent to a database, but

only two of the four checkbox values are stored into two fields in the db.

Critical
The user can not select more than two of the four checkboxes at any given time; the remaing 2 checkboxes must always be

disabled.

Currently
When the page loads the appropriate 2 of the 4 checkboxes are checked and the remaining 2 are unchecked and enabled.

Goal:
(1) When the page loads how do I disabled the 2 unchecked checkboxes.
(2) When the user unchecks 1 of the 2 currently checked checkboxes--enable the other 2 checkboxes which were previously
disabled.
(3) Only 2 of the 4 checkboxes are checked at any given time and the remaining 2 must be disabled.

My code snipet------>When the page loads, my aspx.vb is:

If DSPageData.Tables("ViewSelected").Rows(0).Item("Ty peCode1") = "Q" Or
DSPageData.Tables("ViewSelected").Rows(0).Item("Ty peCode2") = "Q" Then
chkQuality.Checked = True
End If

If DSPageData.Tables("ViewSelected").Rows(0).Item("Ty peCode1") = "F" Or
DSPageData.Tables("ViewSelected").Rows(0).Item("Ty peCode2") = "F" Then
chkFinancial.Checked = True
End If

If DSPageData.Tables("ViewSelected").Rows(0).Item("Ty peCode1") = "C" Or
DSPageData.Tables("ViewSelected").Rows(0).Item("Ty peCode2") = "C" Then
chkCustomer.Checked = True
End If

If DSPageData.Tables("ViewSelected").Rows(0).Item("Ty peCode1") = "E" Or
DSPageData.Tables("ViewSelected").Rows(0).Item("Ty peCode2") = "E" Then
chkEmployee.Checked = True
End If

My .aspx looks like:
<htm>
<head><title>Checkbox and More</title></Head>
<body>
<form>
<table>
<asp:checkbox id="chkQuality" runat="server" Text="Quality" AutoPostBack="True"></asp:checkbox>
<asp:checkbox id="chkFinancial" runat="server" Text="Financial" AutoPostBack="True"></asp:checkbox>

<asp:checkbox id="chkCustomer" runat="server" Text="Customer Service" AutoPostBack="True"></asp:checkbox>
<asp:checkbox id="chkEmployee" runat="server" Text="Employee" AutoPostBack="True"></asp:checkbox>
<asp:button id="btnUpdate" runat="server" Font-Names="Arial" Text="Save"></asp:button>
</table>
</form>
</body>
</html>




 
Old May 14th, 2004, 03:23 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Looks like you're going to have to use JavaScript for this one- ASP can't interact with the page once it's loaded.

You might want to do some Googling for a pre-made script that does this (if there are any).

I'll let you know if I find a solution for you.

Snib

<><
 
Old May 24th, 2004, 12:11 AM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 1,870
Thanks: 12
Thanked 20 Times in 20 Posts
Send a message via AIM to mat41
Default


</html>
<head>
<script>
function countChoices(obj)
{
  max = 2; // max. number allowed at a time
  box1 = obj.form.box1.checked; // your checkboxes here
  box2 = obj.form.box2.checked;
  box3 = obj.form.box3.checked; // add more if necessary

  count = (box1 ? 1 : 0) + (box2 ? 1 : 0) + (box3 ? 1 : 0);
  // If you have more checkboxes on your form
  // add more (box_ ? 1 : 0) 's separated by '+'

  if (count > max)
  {
     alert("Oops! You can only choose up to " + max + " choices! \nUncheck an option if you want to pick another.");
obj.checked = false;
  }
}
-->
</script>
</head>
<body>
<form>
Please choose up to 2 sections:
<p>
<input type=checkbox name=box1 onClick="countChoices(this)">Section 1
<p>
<input type=checkbox name=box2 onClick="countChoices(this)">Section 2
<p>
<input type=checkbox name=box3 onClick="countChoices(this)">Section 3
<p>
</form>
</body>
</html>

Wind is your friend
Matt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Enabling/Disabling Form Controls lbyii Javascript 6 October 13th, 2006 07:36 AM
Enabling and disabling Required field Validators mrufus General .NET 0 June 27th, 2006 03:44 AM
Enabling and Disabling form elements socoolbrewster Javascript How-To 4 February 21st, 2006 04:45 PM
Disabling/enabling the textbox of EditCommandColu ninel ASP.NET 1.0 and 1.1 Professional 1 February 20th, 2006 04:39 PM
MS-Outlook, enabling/disabling rules shamigc VBScript 0 August 4th, 2004 08:57 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.