regarding checkbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yash777
    New Member
    • Mar 2008
    • 20

    regarding checkbox

    hello all,

    this is my first post on the site.

    I just want to Know the javascript which is used to disable the checkboxes on click of another checkbox?

    means if we click on checkbox, the other 2, 3 checkboxes should be disabled.

    Actually, i am retriving Questions and their answers from SQL Server using ASP. And the ID's of these Questions and answers are set as value to the respective checkboxes.

    If, I clicked on the question checkbox then the answers checkboxes should be disabled.

    pl help me
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi yash777,

    Welcome to The Scripts!

    Give this script a try. It's pretty simple and you should be able to adapt it for your own uses.
    Code:
     <html> 
    <head>
     <script type="text/javascript">
     function check()
     {
     var check1 = document.TestForm.Check1
     
     if (check1.checked = true)
      {
      document.TestForm.Check2.checked = false;
      document.TestForm.Check3.checked = false;
      }
     } 
     </script>
    </head>
    <body>
     <form method="post" name="TestForm">
      <input type="checkbox" value="1" name="Check1" onchange="check();">If I check this checkbox...</input>
      <br /><br />
      <input type="checkbox" value="2" name="Check2" checked="checked">This one and...</input>
      <input type="checkbox" value="3" name="Check3" checked="checked">this one should uncheck!</input>
     </form>
    </body>
    </html>
    If you have any problems then please let me know.

    Hope this helps,

    Dr B

    Comment

    • yash777
      New Member
      • Mar 2008
      • 20

      #3
      thanks for ur reply ,

      but Actually i am assigning an ASP value to the checkbox and i want to "disable" the answer checkboxes if a question checkbox is checked.

      As it is coming from database i am not sure of no.of Question and Answer checkboxes.

      Comment

      • yash777
        New Member
        • Mar 2008
        • 20

        #4
        please reply,

        i am not able to reply u again as my office timing is over.

        but pl post ur answer.

        i will check it tomorrow at 10 am.(pl stay connected)

        waiting for ur reply.......... ..........

        Comment

        • DrBunchman
          Recognized Expert Contributor
          • Jan 2008
          • 979

          #5
          Originally posted by yash777
          thanks for ur reply ,

          but Actually i am assigning an ASP value to the checkbox and i want to "disable" the answer checkboxes if a question checkbox is checked.

          As it is coming from database i am not sure of no.of Question and Answer checkboxes.
          I'm afraid I don't understand what it is you're trying to do.

          Can you try to explain it a little more clearly with an example and some code if possible? The clearer the question is the more chance we have of quickly helping you out.

          Dr B

          Comment

          • yash777
            New Member
            • Mar 2008
            • 20

            #6
            thanks for ur reply Dr.B,

            this is my code:

            <%while not rs.eof%>//////first recordset of Questions
            <tr>
            <td height="18" align="center"> <input type="checkbox" name="chkquesti on" value="<%=ID%>" ></td>
            </tr>

            <% while not rsd.eof%>//////second recordset of Answers
            <tr>
            <td height="18" align="center"> <input type="checkbox" name="chksoluti on" value="<%=rsd(" S_id")%>"></td>
            </tr>

            <%wend
            rsd.movenext()

            wend

            rs.movenext()
            %>


            So, i want to disable the answer checkbox if the question checkbox is checked.

            Comment

            • DrBunchman
              Recognized Expert Contributor
              • Jan 2008
              • 979

              #7
              Are the questions and answers coming as pairs? So if I check Question 1(Q1) then Answer 1 (A1) is disabled and if I check Q2 then A2 is disabled and so on?

              Comment

              Working...