Print Page | Close Window

enabling and disabling a checkbox

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=570
Printed Date: 29 March 2026 at 9:42am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: enabling and disabling a checkbox
Posted By: simflex
Subject: enabling and disabling a checkbox
Date Posted: 27 February 2003 at 7:41am
Can someone please help me with this.
I have already come up with the code but it is not working.
What I really need out of this code is to disable all checkboxes except the first one so that processing can be done with that first one.
Once processing is complete with the first one, a checkmark is placed on the checkbox disabling and the next checkbox is enabled for processing.
Once that next one is processed, a checkmark is placed on the checkbox beside it disabling it while enabling the next checkbox for processing until all are processed.
So far, once a checkmark is placed on the first one, everything is disabled.
here is the code i have so far:

<HTML>
<HEAD>
<TITLE>enable</TITLE>
<script language="javascript">
function enable(inBox){
//check to make sure that the last box hasn't been reached.
lastBox = 3;
//disable current box
eval("document.myForm.cb" + inBox + ".disabled = true");
//enable next box (if not finished)
if (inBox < lastBox){
    inBox = inBox + 1;
    eval("document.myForm." + inBox + ".disabled = false");
}
}
</script>

</HEAD>
<BODY>
<form name="myForm">
<table>
<tr>
    <td>First Order
      <input type=checkbox name=cb1 onClick="enable(1)">
    <td>Second Order
      <input type=checkbox name=cb2 onClick="enable(2)" DISABLED>
    <td>Third Order
       <input type=checkbox name=cb3 onClick="enable(3)" DISABLED>
    </td>
   </tr>
</table>
</form>
</BODY>
</HTML>



Replies:
Posted By: MorningZ
Date Posted: 27 February 2003 at 8:21am
"I have already come up with the code but it is not working"
then you haven't come up witht he code yet, lol

here's some that does what i think you are trying to accomplish

<%@ Language=VBScript %>
<HTML>
<HEAD>
<TITLE>enable</TITLE>
<script language="javascript">
<!--
var numOfBoxes = 3;
function enable(inBox) {
     for (var i = inBox + 1; i <= numOfBoxes; i ++) {
          document.forms['myForm']['cb' + i].disabled = false;
     }
}
//-->
</script>

</HEAD>
<BODY>
<form name="myForm">
<table>
<tr>
    <td>First Order
          <input type="checkbox" name="cb1" id="cb1" onClick="enable(1)">
     </td>
    <td>
          Second Order
          <input type="checkbox" name="cb2" id="cb2" onClick="enable(2)" DISABLED>
     </td>
    <td>
          Third Order
       <input type="checkbox" name="cb3" id="cb3" onClick="enable(3)" DISABLED>
    </td>
</tr>
</table>
</form>
</BODY>
</HTML>




-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: MorningZ
Date Posted: 27 February 2003 at 8:24am
btw, to save from copying, pasting, and saving, http://216.119.87.228/sections/playground/scripts/enableCheck.asp - here's that above code running :)


Posted By: simflex
Date Posted: 27 February 2003 at 8:51am

MorningZ, thanks a bunch but it is still not working correctly.

The only time the next checkbox is actived should be after the current checkbox is checked.

For instance, if the first checkbox for first order has not been checked, the rest should be disabled making it impossible for anyone to check them until the first one is checked off as being completed.

again, thanks for the help!



Posted By: MorningZ
Date Posted: 27 February 2003 at 8:56am
so are you saying/asking that the code needs to also deactivate a later checkbox if a user unchecks a box?

ya know, i'd really try to help, but you need to explain better

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: MorningZ
Date Posted: 27 February 2003 at 9:04am
wait i get it now... 5 mins i'll have diff code up

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: MorningZ
Date Posted: 27 February 2003 at 9:09am
http://216.119.87.228/sections/playground/scripts/enableCheck.asp - what about this ?

just "View Source" to see the javascript

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: simflex
Date Posted: 27 February 2003 at 10:38am

Perfect MorningZ!

This is exactly what I need.

You are great and I thank you!

I hope to get to your level one day!




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net