470,566 Members | 1,529 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,566 developers. It's quick & easy.

I want to select two Check Boxs how?

Hi!

In my program, I have multiple check boxs.(more the 10) But i give rights to select 2 check boxs, If i select more then 2 check boxs, I want to display alert message. Please any one post me modle program. Please very very urgent.... any only help me...

By Susan.
Oct 17 '08 #1
17 2415
shweta123
692 Expert 512MB
Hi,

You can try the following code in order to check the multiple checkboxes in your code :

Expand|Select|Wrap|Line Numbers
  1.  
  2.          Dim chk As CheckBox
  3.         Dim cnt As Integer =0
  4.  
  5.        ''This loop will check for all the checkboxex on the form
  6.  
  7.        For index As Integer = 0 To Me.Controls.Count - 1
  8.             If (Me.Controls(index).GetType.Name = "CheckBox") Then
  9.                 chk = CType(Me.Controls(index), CheckBox)
  10.  
  11.                 ''The count variable is taken in order to check how many checkboxes are checked by the user
  12.  
  13.                 If (chk.Checked) Then
  14.                     cnt += 1
  15.                 End If
  16.             End If
  17.         Next
  18.  
  19.        ''Display the alert message after checking the cnt variable value
  20.         If (cnt > 2) Then
  21.             MsgBox("alert message")
  22.         End If
  23.  
Oct 17 '08 #2
Hello!

Thankyou for your reply. In my project, i use only ASP and javascript. Pls send me model program in javascript. I don't know how to use dim chk AS checkbox to javascript. I am beginner for ASP and javascript, so pls help me...

Thanks and Regards,
Susan



Hi,

You can try the following code in order to check the multiple checkboxes in your code :

Expand|Select|Wrap|Line Numbers
  1.  
  2.          Dim chk As CheckBox
  3.         Dim cnt As Integer =0
  4.  
  5.        ''This loop will check for all the checkboxex on the form
  6.  
  7.        For index As Integer = 0 To Me.Controls.Count - 1
  8.             If (Me.Controls(index).GetType.Name = "CheckBox") Then
  9.                 chk = CType(Me.Controls(index), CheckBox)
  10.  
  11.                 ''The count variable is taken in order to check how many checkboxes are checked by the user
  12.  
  13.                 If (chk.Checked) Then
  14.                     cnt += 1
  15.                 End If
  16.             End If
  17.         Next
  18.  
  19.        ''Display the alert message after checking the cnt variable value
  20.         If (cnt > 2) Then
  21.             MsgBox("alert message")
  22.         End If
  23.  
Oct 20 '08 #3
Hi,

You can try the following code in order to check the multiple checkboxes in your code :

Expand|Select|Wrap|Line Numbers
  1.  
  2.          Dim chk As CheckBox
  3.         Dim cnt As Integer =0
  4.  
  5.        ''This loop will check for all the checkboxex on the form
  6.  
  7.        For index As Integer = 0 To Me.Controls.Count - 1
  8.             If (Me.Controls(index).GetType.Name = "CheckBox") Then
  9.                 chk = CType(Me.Controls(index), CheckBox)
  10.  
  11.                 ''The count variable is taken in order to check how many checkboxes are checked by the user
  12.  
  13.                 If (chk.Checked) Then
  14.                     cnt += 1
  15.                 End If
  16.             End If
  17.         Next
  18.  
  19.        ''Display the alert message after checking the cnt variable value
  20.         If (cnt > 2) Then
  21.             MsgBox("alert message")
  22.         End If
  23.  
Hello sir!

I try in javascript, but is show error... (Line:57, char:1, Error: Object expected)
pls check my coding... and kindly me, because i try this program more than 2 days pls help me...

Expand|Select|Wrap|Line Numbers
  1. function disp_alert(){ 
  2.     var canSubmit = true;
  3.     var cnt=0;
  4.     var chk_fields = new Array();
  5.     chk_fields[0] = "chk_m1";
  6.     chk_fields[1] = "chk_m2";
  7.     chk_fields[2] = "chk_m3";
  8.     chk_fields[3] = "chk_n1";
  9.     chk_fields[4] = "chk_n2";
  10.     chk_fields[5] = "chk_n3";
  11.     chk_fields[6] = "chk_nt1";
  12.     chk_fields[7] = "chk_nt2";
  13.     chk_fields[8] = "chk_nt3";
  14.     chk_fields[9] = "chk_s1";
  15.  
  16.     for(var g =0; g <chk_fields.length ;g++){
  17.         var fieldname = chk_fields[g];
  18.         var fieldvalue = document.getElementById(fieldname).checked;
  19.         if(fieldvalue == true){
  20.         alert(fieldvalue);
  21.             cnt = cnt+1;
  22.             }
  23.         }
  24.         alert(cnt);
  25.         if(cnt <= 2 ){
  26.             canSubmit = true;
  27.         }
  28.         else{
  29.         document.getElementById("SPAN_confirm").innerHTML = "select 2 checkbox.";
  30.             canSubmit = false;
  31.             }
  32.     }
  33.     if(canSubmit == true) {
  34.             //alert("submit the form");
  35.             document.frmSubject.submit();
  36.         }
  37. }
My asp coding:

Expand|Select|Wrap|Line Numbers
  1. <%pathdefiner="../"%>
  2. <!-- #include file="../Connection/connector.asp" -->
  3.  
  4. <%
  5. dim rsSql,rsctSql
  6. dim a
  7. dim ctstatus
  8.  
  9.     Set rs = Server.CreateObject("ADODB.Recordset")
  10.     Set rs.ActiveConnection = my_Conn
  11.  
  12. rsSql= "SELECT * FROM " & TBL_Data &" where "& TFL_IDNO & " = '" & Session.Contents("IDNO") & "';"
  13.  
  14. rs.Source = rsSql
  15. rs.Open
  16.  
  17. WHILE NOT rs.EOF
  18.  
  19. %>
  20. <!--#include file="../MainMenu/Header.htm" -->
  21.  
  22.  
  23. <form id="form1" name="form1" method="post" action="">
  24.   <p>your Accept one subject.</p>
  25.   <table width="366" border="0" cellspacing="0" cellpadding="0">
  26.  
  27.   <%
  28.     if rs("Moe") = "MOE" then 
  29.            if rs("moeChoice1") =  "NIL" then
  30.         else        
  31.         %>
  32.         <tr>
  33.         <td width="30"><label>
  34.         <input type="checkbox" name="chk_m1" id="chk_m1"> 
  35.       </label></td>
  36.         <td width="56"><label>
  37.           <input name="textfield11" type="text" id="textfield11" value="<% = rs("Moe") %>" size="3" maxlength="3">
  38.         </label></td>
  39.         <td width="280"><label>
  40.           <input name="textfield" type="text" id="textfield" value="<% = rs("moeChoice1")%>" size="35">
  41.         </label></td>
  42.       </tr>
  43.        <% end if 
  44.        if rs("moeChoice2") =  "NIL" then
  45.         else
  46.        %>
  47.        <tr><td width="30"><label>
  48.        <input type="checkbox" name="chk_m2" id="chk_m2">
  49.        </label></td>
  50.          <td width="56"><label>
  51.            <input name="textfield12" type="text" id="textfield12" value="<% = rs("Moe") %>" size="3" maxlength="3">
  52.          </label></td>
  53.          <td width="280"><label>
  54.            <input name="textfield2" type="text" id="textfield2" value="<% = rs("moeChoice2")%>" size="35">
  55.          </label></td>
  56.       </tr>
  57.        <% end if 
  58.        if rs("moeChoice3") =  "NIL" then
  59.         else
  60.        %>
  61.        <tr><td width="30"><label>
  62.        <input type="checkbox" name="chk_m3" id="chk_m3">
  63.        </label></td>
  64.          <td width="56"><label>
  65.            <input name="textfield13" type="text" id="textfield13" value="<% = rs("Moe") %>" size="3" maxlength="3">
  66.          </label></td>
  67.          <td width="280"><label>
  68.            <input name="textfield3" type="text" id="textfield3" value="<% = rs("moeChoice3")%>" size="35">
  69.          </label></td>
  70.       </tr>
  71.     <% 
  72.     end if //moe choices endif
  73.     end if  // moe end if
  74.     //-------------- Nus ---------------------//
  75.     if rs("Nus") = "NUS" then 
  76.            if rs("nusChoice1") =  "NIL" then
  77.         else        
  78.         %>
  79.         <tr>
  80.         <td width="30"><label>
  81.         <input type="checkbox" name="chk_n1" id="chk_n1">
  82.         </label></td>
  83.         <td width="56"><label>
  84.           <input name="textfield14" type="text" id="textfield14" value="<% = rs("Nus") %>" size="3" maxlength="3">
  85.         </label></td>
  86.         <td width="280"><label>
  87.           <input name="textfield4" type="text" id="textfield4" value="<% = rs("nusChoice1")%>" size="35">
  88.         </label></td>
  89.       </tr>
  90.        <% end if 
  91.        if rs("nusChoice2") =  "NIL" then
  92.         else
  93.        %>
  94.        <tr><td width="30"><label>
  95.        <input type="checkbox" name="chk_n2" id="chk_n2">
  96.        </label></td>
  97.          <td width="56"><label>
  98.            <input name="textfield15" type="text" id="textfield15" value="<% = rs("Nus") %>" size="3" maxlength="3">
  99.          </label></td>
  100.          <td width="280"><label>
  101.            <input name="textfield5" type="text" id="textfield5" value="<% = rs("nusChoice2")%>" size="35">
  102.          </label></td>
  103.       </tr>
  104.        <% end if 
  105.        if rs("nusChoice3") =  "NIL" then
  106.         else
  107.        %>
  108.        <tr><td width="30"><label>
  109.        <input type="checkbox" name="chk_n3" id="chk_n3">
  110.        </label></td>
  111.          <td width="56"><label>
  112.            <input name="textfield16" type="text" id="textfield16" value="<% = rs("Nus") %>" size="3" maxlength="3">
  113.          </label></td>
  114.          <td width="280"><label>
  115.            <input name="textfield6" type="text" id="textfield6" value="<% = rs("nusChoice3")%>" size="35">
  116.          </label></td>
  117.       </tr>
  118.     <% 
  119.     end if //Nus choices endif
  120.     end if  // Nus end if
  121.  
  122.     //-------------- Ntu ---------------------//
  123.     if rs("Ntu") = "NTU" then 
  124.            if rs("ntuChoice1") =  "NIL" then
  125.         else        
  126.         %>
  127.         <tr>
  128.         <td width="30"><label>
  129.         <input type="checkbox" name="chk_nt1" id="chk_nt1">
  130.         </label></td>
  131.         <td width="56"><label>
  132.           <input name="textfield17" type="text" id="textfield17" value="<% = rs("Ntu") %>" size="3" maxlength="3">
  133.         </label></td>
  134.         <td width="280"><label>
  135.           <input name="textfield7" type="text" id="textfield7" value="<% = rs("ntuChoice1")%>" size="35">
  136.         </label></td>
  137.       </tr>
  138.        <% end if 
  139.        if rs("ntuChoice2") =  "NIL" then
  140.         else
  141.        %>
  142.        <tr><td width="30"><label>
  143.        <input type="checkbox" name="chk_nt2" id="chk_nt2">
  144.        </label></td>
  145.          <td width="56"><label>
  146.            <input name="textfield18" type="text" id="textfield18" value="<% = rs("Ntu") %>" size="3" maxlength="3">
  147.          </label></td>
  148.          <td width="280"><label>
  149.            <input name="textfield8" type="text" id="textfield8" value="<% = rs("ntuChoice2")%>" size="35">
  150.          </label></td>
  151.       </tr>
  152.        <% end if 
  153.        if rs("ntuChoice3") =  "NIL" then
  154.         else
  155.        %>
  156.        <tr><td width="30"><label>
  157.        <input type="checkbox" name="chk_nt3" id="chk_nt3">
  158.        </label></td>
  159.          <td width="56"><label>
  160.            <input name="textfield19" type="text" id="textfield19" value="<% = rs("Ntu") %>" size="3" maxlength="3">
  161.          </label></td>
  162.          <td width="280"><label>
  163.            <input name="textfield9" type="text" id="textfield9" value="<% = rs("ntuChoice3")%>" size="35">
  164.          </label></td>
  165.       </tr>
  166.     <% 
  167.     end if //ntu choices endif
  168.     end if  // ntu end if
  169.     //-------------- Smu ---------------------//
  170.     if rs("Smu") = "SMU" then 
  171.            if rs("smuChoice1") =  "NIL" then
  172.         else        
  173.         %>
  174.         <tr>
  175.         <td width="30"><label>
  176.         <input type="checkbox" name="chk_s1" id="chk_s1">
  177.         </label></td>
  178.         <td width="56"><label>
  179.           <input name="textfield20" type="text" id="textfield20" value="<% = rs("Smu") %>" size="3" maxlength="3">
  180.         </label></td>
  181.         <td width="280"><label>
  182.           <input name="textfield10" type="text" id="textfield10" value="<% = rs("smuChoice1")%>" size="35">
  183.         </label></td>
  184.       </tr>
  185.  
  186.  
  187.     <% 
  188.  
  189.     end if //ntu choices endif
  190.     end if
  191.  
  192.  rs.MoveNext
  193.  WEND
  194.     rs.Close
  195.     my_Conn.Close
  196.     set rs=nothing
  197.     set my_Conn=nothing
  198.     Response.Expires = -1 
  199.  
  200. %>
  201. <tr>
  202.           <td>&nbsp;</td>
  203.           <td>&nbsp;</td>
  204.           <td><label>
  205.             <input type="button" name="submit" id="submit" value="Submit" onClick="javascript:disp_alert();">
  206.           </label></td>
  207.         </tr>
  208.   </table>
  209.   <p>&nbsp;  </p>
  210. </form>
  211. <!--#include file="../MainMenu/Footer.htm" -->
  212.  
  213.  
Oct 20 '08 #4
In my program, I have multiple check boxs.(more the 10) But i give rights to select 2 check boxs, If i select more then 2 check boxs, I want to display alert message. pls send me model program in javascript using asp or give idea.

In table data base is below:

MOE/ H3 Economics / Nil / Nil / NUS / Physics / Nil / Nil / 'blank' / Nil /Nil /Nil / SMU /Games

in Form the check box is display like this:

1. Here one checkbox - MOE H3 Economics
2. Here one checkbox - NUS Physics
3. Here one checkbox - SMU Games

Now i give rights to select two checkboxes. How?

I try my self, but i didn't got answer, because in my program i check all checkbox in array, so the loop in not finished. i thought the error in array.

below my asp and javascript coding:
Expand|Select|Wrap|Line Numbers
  1. <%pathdefiner="../"%>
  2. <!-- #include file="../Connection/connector.asp" -->
  3.  
  4. <%
  5. dim rsSql,rsctSql
  6. dim a
  7. dim ctstatus
  8.  
  9.     Set rs = Server.CreateObject("ADODB.Recordset")
  10.     Set rs.ActiveConnection = my_Conn
  11.  
  12. rsSql= "SELECT * FROM " & TBL_Data &" where "& TFL_IDNO & " = '" & Session.Contents("IDNO") & "';"
  13.  
  14. rs.Source = rsSql
  15. rs.Open
  16.  
  17. WHILE NOT rs.EOF
  18.  
  19. %>
  20. <!--#include file="../MainMenu/Header.htm" -->
  21.  
  22. <form id="frmUpdate" name="frmUpdate" method="post" action="welcome.asp">
  23.   <p>your Accept one subject.</p>
  24.   <table width="366" border="0" cellspacing="0" cellpadding="0">
  25.   <%
  26.     if rs("Moe") = "MOE" then 
  27.            if rs("moeChoice1") =  "NIL" then
  28.         else        
  29.         %>
  30.         <tr>
  31.         <td width="30"><label>
  32.         <input type="checkbox" name="chk_m1" id="chk_m1"> 
  33.       </label></td>
  34.         <td width="56"><label>
  35.           <input name="textfield11" type="text" id="textfield11" value="<% = rs("Moe") %>" size="3" maxlength="3">
  36.         </label></td>
  37.         <td width="280"><label>
  38.           <input name="textfield" type="text" id="textfield" value="<% = rs("moeChoice1")%>" size="35">
  39.         </label></td>
  40.       </tr>
  41.        <% end if 
  42.        if rs("moeChoice2") =  "NIL" then
  43.         else
  44.        %>
  45.        <tr><td width="30"><label>
  46.        <input type="checkbox" name="chk_m2" id="chk_m2">
  47.        </label></td>
  48.          <td width="56"><label>
  49.            <input name="textfield12" type="text" id="textfield12" value="<% = rs("Moe") %>" size="3" maxlength="3">
  50.          </label></td>
  51.          <td width="280"><label>
  52.            <input name="textfield2" type="text" id="textfield2" value="<% = rs("moeChoice2")%>" size="35">
  53.          </label></td>
  54.       </tr>
  55.        <% end if 
  56.        if rs("moeChoice3") =  "NIL" then
  57.         else
  58.  
  59.        %>
  60.        <tr><td width="30"><label>
  61.        <input type="checkbox" name="chk_m3" id="chk_m3">
  62.        </label></td>
  63.          <td width="56"><label>
  64.            <input name="textfield13" type="text" id="textfield13" value="<% = rs("Moe") %>" size="3" maxlength="3">
  65.          </label></td>
  66.          <td width="280"><label>
  67.            <input name="textfield3" type="text" id="textfield3" value="<% = rs("moeChoice3")%>" size="35">
  68.          </label></td>
  69.       </tr>
  70.     <% 
  71.     end if //moe choices endif
  72.     end if  // moe end if
  73.     //-------------- Nus ---------------------//
  74.     if rs("Nus") = "NUS" then 
  75.            if rs("nusChoice1") =  "NIL" then
  76.         else        
  77.         %>
  78.         <tr>
  79.         <td width="30"><label>
  80.         <input type="checkbox" name="chk_n1" id="chk_n1">
  81.         </label></td>
  82.         <td width="56"><label>
  83.           <input name="textfield14" type="text" id="textfield14" value="<% = rs("Nus") %>" size="3" maxlength="3">
  84.         </label></td>
  85.         <td width="280"><label>
  86.           <input name="textfield4" type="text" id="textfield4" value="<% = rs("nusChoice1")%>" size="35">
  87.         </label></td>
  88.       </tr>
  89.        <% end if 
  90.        if rs("nusChoice2") =  "NIL" then
  91.         else
  92.        %>
  93.        <tr><td width="30"><label>
  94.        <input type="checkbox" name="chk_n2" id="chk_n2">
  95.        </label></td>
  96.          <td width="56"><label>
  97.            <input name="textfield15" type="text" id="textfield15" value="<% = rs("Nus") %>" size="3" maxlength="3">
  98.          </label></td>
  99.          <td width="280"><label>
  100.            <input name="textfield5" type="text" id="textfield5" value="<% = rs("nusChoice2")%>" size="35">
  101.          </label></td>
  102.       </tr>
  103.        <% end if 
  104.        if rs("nusChoice3") =  "NIL" then
  105.         else
  106.        %>
  107.        <tr><td width="30"><label>
  108.        <input type="checkbox" name="chk_n3" id="chk_n3">
  109.        </label></td>
  110.          <td width="56"><label>
  111.            <input name="textfield16" type="text" id="textfield16" value="<% = rs("Nus") %>" size="3" maxlength="3">
  112.          </label></td>
  113.          <td width="280"><label>
  114.            <input name="textfield6" type="text" id="textfield6" value="<% = rs("nusChoice3")%>" size="35">
  115.          </label></td>
  116.       </tr>
  117.     <% 
  118.     end if //Nus choices endif
  119.     end if  // Nus end if
  120.  
  121.     //-------------- Ntu ---------------------//
  122.     if rs("Ntu") = "NTU" then 
  123.            if rs("ntuChoice1") =  "NIL" then
  124.         else        
  125.         %>
  126.         <tr>
  127.         <td width="30"><label>
  128.         <input type="checkbox" name="chk_nt1" id="chk_nt1">
  129.         </label></td>
  130.         <td width="56"><label>
  131.           <input name="textfield17" type="text" id="textfield17" value="<% = rs("Ntu") %>" size="3" maxlength="3">
  132.         </label></td>
  133.         <td width="280"><label>
  134.           <input name="textfield7" type="text" id="textfield7" value="<% = rs("ntuChoice1")%>" size="35">
  135.         </label></td>
  136.       </tr>
  137.        <% end if 
  138.        if rs("ntuChoice2") =  "NIL" then
  139.         else
  140.        %>
  141.        <tr><td width="30"><label>
  142.        <input type="checkbox" name="chk_nt2" id="chk_nt2">
  143.        </label></td>
  144.          <td width="56"><label>
  145.            <input name="textfield18" type="text" id="textfield18" value="<% = rs("Ntu") %>" size="3" maxlength="3">
  146.          </label></td>
  147.          <td width="280"><label>
  148.            <input name="textfield8" type="text" id="textfield8" value="<% = rs("ntuChoice2")%>" size="35">
  149.          </label></td>
  150.       </tr>
  151.        <% end if 
  152.        if rs("ntuChoice3") =  "NIL" then
  153.         else
  154.        %>
  155.        <tr><td width="30"><label>
  156.        <input type="checkbox" name="chk_nt3" id="chk_nt3">
  157.        </label></td>
  158.          <td width="56"><label>
  159.            <input name="textfield19" type="text" id="textfield19" value="<% = rs("Ntu") %>" size="3" maxlength="3">
  160.          </label></td>
  161.          <td width="280"><label>
  162.            <input name="textfield9" type="text" id="textfield9" value="<% = rs("ntuChoice3")%>" size="35">
  163.          </label></td>
  164.       </tr>
  165.     <% 
  166.     end if //ntu choices endif
  167.     end if  // ntu end if
  168.     //-------------- Smu ---------------------//
  169.     if rs("Smu") = "SMU" then 
  170.            if rs("smuChoice1") =  "NIL" then
  171.         else        
  172.         %>
  173.         <tr>
  174.         <td width="30"><label>
  175.         <input type="checkbox" name="chk_s1" id="chk_s1">
  176.         </label></td>
  177.         <td width="56"><label>
  178.           <input name="textfield20" type="text" id="textfield20" value="<% = rs("Smu") %>" size="3" maxlength="3">
  179.         </label></td>
  180.         <td width="280"><label>
  181.           <input name="textfield10" type="text" id="textfield10" value="<% = rs("smuChoice1")%>" size="35">
  182.         </label></td>
  183.       </tr>
  184.  
  185.  
  186.     <% 
  187.  
  188.     end if //ntu choices endif
  189.     end if
  190.  
  191.  rs.MoveNext
  192.  WEND
  193.     rs.Close
  194.     my_Conn.Close
  195.     set rs=nothing
  196.     set my_Conn=nothing
  197.     Response.Expires = -1 
  198.  
  199. %>
  200. <tr>
  201.           <td>&nbsp;</td>
  202.           <td>&nbsp;</td>
  203.           <td></td>
  204.         </tr>
  205.         <tr>
  206.           <td>&nbsp;</td>
  207.           <td>&nbsp;</td>
  208.           <td><br><span id="SPAN_confirm"></span> </td>
  209.         </tr>
  210.        </table>
  211.   <p>&nbsp;  </p>
  212.   <label>
  213.             <input type="button" name="Button" id="submit" value="Button" onClick="javascript:alertmess(),disp_alert();">
  214.           </label>
  215. </form>
  216. <!--#include file="../MainMenu/Footer.htm" -->
  217.  
Expand|Select|Wrap|Line Numbers
  1. javascript coding:
  2. // JavaScript Document
  3.  
  4. function alertmess(){
  5.     alert('Hello from JavaScript!');
  6. }
  7.  
  8. function disp_alert(){ 
  9.     var canSubmit;
  10.     var cnt=0;
  11.  
  12.     var chk_fields = new Array();
  13.     chk_fields[0] = "chk_m1";
  14.     chk_fields[1] = "chk_m2";
  15.     chk_fields[2] = "chk_m3";
  16.     chk_fields[3] = "chk_n1";
  17.     chk_fields[4] = "chk_n2";
  18.     chk_fields[5] = "chk_n3";
  19.     chk_fields[6] = "chk_nt1";
  20.     chk_fields[7] = "chk_nt2";
  21.     chk_fields[8] = "chk_nt3";
  22.     chk_fields[9] = "chk_s1";
  23.  
  24.     for(var g =0; g <chk_fields.length ;g++){
  25.         var fieldname = chk_fields[g];
  26.         var fieldvalue = document.getElementById(fieldname).checked;
  27.         if(fieldvalue!="NIL"){
  28.             if(fieldvalue == true){
  29.  
  30.             cnt = cnt+1;
  31.             }
  32.         }
  33.  
  34.     }
  35.  
  36.         if(cnt == 2 ){
  37.         document.getElementById("SPAN_confirm").innerHTML = "";
  38.         canSubmit = true;
  39.         }
  40.         else{
  41.         document.getElementById("SPAN_confirm").innerHTML = "select 2 checkbox.";
  42.         canSubmit = false; 
  43.         }
  44.  
  45.     if(canSubmit == true){
  46.         document.frmUpdate.submit();
  47.     }
  48. }
Oct 20 '08 #5
shweta123
692 Expert 512MB
Hi,

1> If you want to fill the checkboxes using database table you can do it using following method :

Expand|Select|Wrap|Line Numbers
  1.  
  2. <% 
  3.     dim rsSql,rsctSql 
  4.     dim a 
  5.    dim ctstatus 
  6.  
  7.     Set rs = Server.CreateObject("ADODB.Recordset") 
  8.     Set rs.ActiveConnection = my_Conn 
  9.  
  10.    rsSql= "SELECT * FROM " & TBL_Data &" where "& TFL_IDNO & " = '" &      Session.Contents("IDNO") & "';" 
  11.  
  12.      rs.Source = rsSql 
  13.      rs.Open 
  14.  
  15.     WHILE NOT rs.EOF %>
  16.    <input type="checkbox" name="chkboxes" value = <%= rs("fielname")>>
  17.    <%= rs("fielname")>
  18.    <%
  19.      rs.moveNext
  20.     WEND%>  
  21.  
In the above code :

1> The NAME value is crucial. For all our check boxes, the NAME is the same - "chkboxes".

2 > The text that people see on the page comes after the right angle bracket ( > ).

3> The VALUE of the checkbox is the same as the text that people see on the page. (But it doesn't have to be).



2> You can write the following code in javascript to allow only two checkboxes to be checked.

Expand|Select|Wrap|Line Numbers
  1. function myFunction
  2. {
  3.  
  4.      //Check how many checkboxes are on the form
  5.      boxes = document.form1.chkboxes.length
  6.  
  7.     //Check for all the checkboxes on the form using the loop
  8.      var chkCnt;
  9.      for (i = 0; i < boxes; i++)
  10.        {
  11.          if (document.form1.chkboxes[i].checked) 
  12.          {
  13.             chkCnt++;
  14.          }
  15.       }
  16.  
  17.      if(chkCnt > 2)
  18.          {
  19.            return false;
  20.          }
  21.       return true;
  22.      }
  23.  
3>Call the above javascript function on the Submit button click.
<input type= "Submit text = "Submit" onClick = "myFunction()" >
Oct 20 '08 #6
Hello Sir!

Thankyou for your reply.

I followed your steps, but i didn't got answer.
1) If i select more than 2 check boxs and click submit button, it's display alert message.
2) If i select one or two check box and click submit button, it is not go to next page. why i don't know?
Pls check the submit button: <input type="button" name="submit" id="submit" value="Submit" onClick="javascript:myFunction();">

Pls help me, because i try this program more than 5 days, tomorrow i want to finished my work. so check my coding and help me......

javascript:
Expand|Select|Wrap|Line Numbers
  1. function myFunction() 
  2.      //Check how many checkboxes are on the form 
  3.      boxes = document.frmUpdate.chkboxes.length 
  4.  
  5.     //Check for all the checkboxes on the form using the loop 
  6.      var chkCnt=0; 
  7.      for (i = 0; i < boxes; i++) 
  8.        { 
  9.          if (document.frmUpdate.chkboxes[i].checked)  
  10.          { 
  11.             chkCnt++; 
  12.          } 
  13.       } 
  14.  
  15.      if(chkCnt > 2) 
  16.          { 
  17.          alert("Select two Subject");
  18.               return false; 
  19.          } 
  20.       return true; 
  21.  
  22.  
ASP program:

Expand|Select|Wrap|Line Numbers
  1. <%pathdefiner="../"%>
  2. <!-- #include file="../Connection/connector.asp" -->
  3.  
  4. <%
  5. dim rsSql,rsctSql
  6. dim a
  7. dim ctstatus
  8.  
  9.     Set rs = Server.CreateObject("ADODB.Recordset")
  10.     Set rs.ActiveConnection = my_Conn
  11.  
  12. rsSql= "SELECT * FROM " & TBL_Data &" where "& TFL_IDNO & " = '" & Session.Contents("IDNO") & "';"
  13.  
  14. rs.Source = rsSql
  15. rs.Open
  16.  
  17. WHILE NOT rs.EOF
  18.  
  19. %>
  20. <!--#include file="../MainMenu/Header.htm" -->
  21.  
  22. <form id="frmUpdate" name="frmUpdate" method="post" action="welcome.asp">
  23.   <p>your Accept one subject.</p>
  24.   <table width="366" border="0" cellspacing="0" cellpadding="0">
  25.   <%
  26.     if rs("Moe") = "MOE" then 
  27.            if rs("moeChoice1") =  "NIL" then
  28.         else        
  29.         %>
  30.         <tr>
  31.         <td width="30"><label>
  32.         <input type="checkbox" name="chkboxes" id="chk_m1"  > 
  33.       </label></td>
  34.         <td width="56"><label>
  35.           <input name="textfield11" type="text" id="textfield11" value="<% = rs("Moe") %>" size="3" maxlength="3">
  36.         </label></td>
  37.         <td width="280"><label>
  38.           <input name="textfield" type="text" id="textfield" value="<% = rs("moeChoice1")%>" size="35">
  39.         </label></td>
  40.       </tr>
  41.        <% end if 
  42.        if rs("moeChoice2") =  "NIL" then
  43.         else
  44.        %>
  45.        <tr><td width="30"><label>
  46.        <input type="checkbox" name="chkboxes" id="chk_m2"  >
  47.        </label></td>
  48.          <td width="56"><label>
  49.            <input name="textfield12" type="text" id="textfield12" value="<% = rs("Moe") %>" size="3" maxlength="3">
  50.          </label></td>
  51.          <td width="280"><label>
  52.            <input name="textfield2" type="text" id="textfield2" value="<% = rs("moeChoice2")%>" size="35">
  53.          </label></td>
  54.       </tr>
  55.        <% end if 
  56.        if rs("moeChoice3") =  "NIL" then
  57.         else
  58.  
  59.        %>
  60.        <tr><td width="30"><label>
  61.        <input type="checkbox" name="chkboxes" id="chk_m3"  >
  62.        </label></td>
  63.          <td width="56"><label>
  64.            <input name="textfield13" type="text" id="textfield13" value="<% = rs("Moe") %>" size="3" maxlength="3">
  65.          </label></td>
  66.          <td width="280"><label>
  67.            <input name="textfield3" type="text" id="textfield3" value="<% = rs("moeChoice3")%>" size="35">
  68.          </label></td>
  69.       </tr>
  70.     <% 
  71.     end if //moe choices endif
  72.     end if  // moe end if
  73.     //-------------- Nus ---------------------//
  74.     if rs("Nus") = "NUS" then 
  75.            if rs("nusChoice1") =  "NIL" then
  76.         else        
  77.         %>
  78.         <tr>
  79.         <td width="30"><label>
  80.         <input type="checkbox" name="chkboxes" id="chk_n1"  >
  81.         </label></td>
  82.         <td width="56"><label>
  83.           <input name="textfield14" type="text" id="textfield14" value="<% = rs("Nus") %>" size="3" maxlength="3">
  84.         </label></td>
  85.         <td width="280"><label>
  86.           <input name="textfield4" type="text" id="textfield4" value="<% = rs("nusChoice1")%>" size="35">
  87.         </label></td>
  88.       </tr>
  89.        <% end if 
  90.        if rs("nusChoice2") =  "NIL" then
  91.         else
  92.        %>
  93.        <tr><td width="30"><label>
  94.        <input type="checkbox" name="chkboxes" id="chk_n2"  >
  95.        </label></td>
  96.          <td width="56"><label>
  97.            <input name="textfield15" type="text" id="textfield15" value="<% = rs("Nus") %>" size="3" maxlength="3">
  98.          </label></td>
  99.          <td width="280"><label>
  100.            <input name="textfield5" type="text" id="textfield5" value="<% = rs("nusChoice2")%>" size="35">
  101.          </label></td>
  102.       </tr>
  103.        <% end if 
  104.        if rs("nusChoice3") =  "NIL" then
  105.         else
  106.        %>
  107.        <tr><td width="30"><label>
  108.        <input type="checkbox" name="chkboxes" id="chk_n3"  >
  109.        </label></td>
  110.          <td width="56"><label>
  111.            <input name="textfield16" type="text" id="textfield16" value="<% = rs("Nus") %>" size="3" maxlength="3">
  112.          </label></td>
  113.          <td width="280"><label>
  114.            <input name="textfield6" type="text" id="textfield6" value="<% = rs("nusChoice3")%>" size="35">
  115.          </label></td>
  116.       </tr>
  117.     <% 
  118.     end if //Nus choices endif
  119.     end if  // Nus end if
  120.  
  121.     //-------------- Ntu ---------------------//
  122.     if rs("Ntu") = "NTU" then 
  123.            if rs("ntuChoice1") =  "NIL" then
  124.         else        
  125.         %>
  126.         <tr>
  127.         <td width="30"><label>
  128.         <input type="checkbox" name="chkboxes" id="chk_nt1"  >
  129.         </label></td>
  130.         <td width="56"><label>
  131.           <input name="textfield17" type="text" id="textfield17" value="<% = rs("Ntu") %>" size="3" maxlength="3">
  132.         </label></td>
  133.         <td width="280"><label>
  134.           <input name="textfield7" type="text" id="textfield7" value="<% = rs("ntuChoice1")%>" size="35">
  135.         </label></td>
  136.       </tr>
  137.        <% end if 
  138.        if rs("ntuChoice2") =  "NIL" then
  139.         else
  140.        %>
  141.        <tr><td width="30"><label>
  142.        <input type="checkbox" name="chkboxes" id="chk_nt2"  >
  143.        </label></td>
  144.          <td width="56"><label>
  145.            <input name="textfield18" type="text" id="textfield18" value="<% = rs("Ntu") %>" size="3" maxlength="3">
  146.          </label></td>
  147.          <td width="280"><label>
  148.            <input name="textfield8" type="text" id="textfield8" value="<% = rs("ntuChoice2")%>" size="35">
  149.          </label></td>
  150.       </tr>
  151.        <% end if 
  152.        if rs("ntuChoice3") =  "NIL" then
  153.         else
  154.        %>
  155.        <tr><td width="30"><label>
  156.        <input type="checkbox" name="chkboxes" id="chk_nt3"  >
  157.        </label></td>
  158.          <td width="56"><label>
  159.            <input name="textfield19" type="text" id="textfield19" value="<% = rs("Ntu") %>" size="3" maxlength="3">
  160.          </label></td>
  161.          <td width="280"><label>
  162.            <input name="textfield9" type="text" id="textfield9" value="<% = rs("ntuChoice3")%>" size="35">
  163.          </label></td>
  164.       </tr>
  165.     <% 
  166.     end if //ntu choices endif
  167.     end if  // ntu end if
  168.     //-------------- Smu ---------------------//
  169.     if rs("Smu") = "SMU" then 
  170.            if rs("smuChoice1") =  "NIL" then
  171.         else        
  172.         %>
  173.         <tr>
  174.         <td width="30"><label>
  175.         <input type="checkbox" name="chkboxes" id="chk_s1"  >
  176.         </label></td>
  177.         <td width="56"><label>
  178.           <input name="textfield20" type="text" id="textfield20" value="<% = rs("Smu") %>" size="3" maxlength="3">
  179.         </label></td>
  180.         <td width="280"><label>
  181.           <input name="textfield10" type="text" id="textfield10" value="<% = rs("smuChoice1")%>" size="35">
  182.         </label></td>
  183.       </tr>
  184.  
  185.  
  186.     <% 
  187.  
  188.     end if //ntu choices endif
  189.     end if
  190.  
  191.  rs.MoveNext
  192.  WEND
  193.     rs.Close
  194.     my_Conn.Close
  195.     set rs=nothing
  196.     set my_Conn=nothing
  197.     Response.Expires = -1 
  198.  
  199. %>
  200. <tr>
  201.           <td>&nbsp;</td>
  202.           <td>&nbsp;</td>
  203.           <td></td>
  204.         </tr>
  205.         <tr>
  206.           <td>&nbsp;</td>
  207.           <td>&nbsp;</td>
  208.           <td><br><span id="SPAN_confirm" class="errorcss"></span> </td>
  209.         </tr>
  210.        </table>
  211.   <p>&nbsp;  </p>
  212.   <label>
  213.             <input type="button" name="Button" id="submit" value="Button" onClick="javascript:myFunction();">
  214.           </label>
  215. </form>
  216. <!--#include file="../MainMenu/Footer.htm" -->
  217.  
  218.  
Oct 21 '08 #7
Hi!

I have Multiple checkboxs. But I select only 2 check boxs and i want to store the selected check boxs value in to the database.
How? Pls help me..
Oct 22 '08 #8
HI!

I got answer.
Thankyou soo much!

Again i need your help. I don't know, how store the selected check boxs value in the database? So pls help me....
i want to store the selected check boxs value in to the database.
Oct 22 '08 #9
jhardman
3,406 Expert 2GB
article by markrawlingson
Oct 23 '08 #10
shweta123
692 Expert 512MB
Hi,

Please try the following code in order to insert the values of checkboxes into database.
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Dim i
  3.     Dim sql
  4.     Dim con
  5.  
  6.     ''Open connection
  7.     set con = server.CreateObject("Adodb.Connection")
  8.     con.Open
  9.  
  10.     ''Loop through the collection of Checkboxes
  11.     For i = 1 to Request.Form("chkboxes").Count
  12.         ''Insert checkbox data into db 
  13.         sql = "Insert Into tablename (columnname) Values(Request.Form("chkboxes").Item(i))
  14.         con.Execute(sql)
  15.     Next
  16.  
  17.     con.Close()
  18.  
  19. %>
Oct 23 '08 #11
Hi

Thankyou for your reply.

i got error. I don't know, how to solve?

Below is error message
Technical Information (for support personnel)

Error Type:
Expand|Select|Wrap|Line Numbers
  1. Microsoft JET Database Engine (0x80040E10)
  2. No value given for one or more required parameters.
  3. /H3finalresult/include/Updatesubj2.asp, line 23

Browser Type:
Expand|Select|Wrap|Line Numbers
  1. Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648) 
Page:
Expand|Select|Wrap|Line Numbers
  1. POST 283 bytes to /H3finalresult/include/Updatesubj2.asp
POST Data:
Expand|Select|Wrap|Line Numbers
  1. txt_subjs=H3+Economics&chk_boxes=moe&txt_subjs=H3+Art&txt_subjs=H3+Economics&txt_subjs=Economy+%26+Space&chk_boxes=Ntu&txt_subjs=Contemporary+Physics+@+HCI+%2F+NJC&txt_subjs=Molecular+Biology+@+RJC&tx . . .
Updatesubj2.asp
Expand|Select|Wrap|Line Numbers
  1. <%pathdefiner = "../"%>
  2. <!-- #include file="../connection/connector.asp" -->
  3. <%
  4. Dim boxes, value 
  5.  
  6. value = Request.Form("chk_boxes").Count
  7. updateSql = "UPDATE " & TBL_Data & ", " & TBL_2Subj & " SET "
  8.  
  9.         for i = 1 to Request.Form("chk_boxes").Count 
  10.         'Insert checkbox data into db  '
  11.         updateSql = updateSql & TBL_2Subj & "." & "Uni" & i & " ='" & Request.Form("chk_boxes").Item(i) & "', "
  12.         updateSql = updateSql & TBL_2Subj & "." & "subj" & i & " ='" & Request.Form("txt_subjs").Item(i) & "'"
  13.  
  14.          if i < value then
  15.         updateSql = updateSql & ", "
  16.         end if
  17.  
  18.     //response.write value & "<br>"        
  19.  next
  20. updateSql = updateSql & " WHERE nric='" & Session.Contents("IDNO") &"';"
  21. Response.Write(updateSql)
  22. //response.end
  23. my_Conn.Execute(updateSql)
  24.  
  25. //close connection'
  26. my_Conn.Close
  27. Set my_Conn = Nothing
  28. Response.Redirect("welcome.asp")
  29. %>
Oct 24 '08 #12
jhardman
3,406 Expert 2GB
the error means that there is a field in the db that is required, but your insert or update statement leaves it out. I usually find though that this means there is a misspelling or some such. Print out the updateSQL (response.write updateSQL) and see if there is anything obvious you are missing, or if something is misspelled.

Jared
Oct 24 '08 #13
Hi!

In one form i have multiple check boxes and textboxes.

for ex:
1 row: "checkbox" Car "textbox" Red color
2 row: "checkbox" Car "textbox" Yellow color
3 row: "checkbox" Bicycle "textbox" Green color
4 row: "checkbox" Scooter "textbox" Red and white color
5 row: "checkbox" Bicycle "textbox" Black color

Now i select 2 checkboxs (1st row checkbox and 4th row checkbox).
i want to pass the 1st row checkbox and textbox value (Car, Red color) and 4th row checkbox and textbox value(Scooter, Red and white color) pass into database. How? I didn't want to store the remining checkboxs and textboxs value. I want to store the selected rows checkbox and textbox value.

please help me.... It's very very urgent work.....
Oct 30 '08 #14
Hi!

In one form i have multiple check boxes and textboxes.

for ex:
1 row: "checkbox" Car "textbox" Red color
2 row: "checkbox" Car "textbox" Yellow color
3 row: "checkbox" Bicycle "textbox" Green color
4 row: "checkbox" Scooter "textbox" Red and white color
5 row: "checkbox" Bicycle "textbox" Black color

Now i select 2 checkboxs (1st row checkbox and 4th row checkbox).
i want to pass the 1st row checkbox and textbox value (Car, Red color) and 4th row checkbox and textbox value(Scooter, Red and white color) pass into database. How? I didn't want to store the remining checkboxs and textboxs value. I want to store the selected rows checkbox and textbox value.

please help me.... It's very very urgent work.....

Pls send me model program
by
susan
Oct 30 '08 #15
Hello Sir/Madam/Friends!

Please help me. I didn't have experience in asp. i didn't have friend in asp platform. So pls kindly help me...

In one form i have multiple check boxes and textboxes.

for ex:
1 row: "checkbox" Car "textbox" Red color
2 row: "checkbox" Car "textbox" Yellow color
3 row: "checkbox" Bicycle "textbox" Green color
4 row: "checkbox" Scooter "textbox" Red and white color
5 row: "checkbox" Bicycle "textbox" Black color

Now i select 2 checkboxs (1st and 4th).
i want to pass the 1st row checkbox and textbox value (Car, Red color) and 4th row checkbox and textbox value(Scooter, Red and white color) pass into database. How? I didn't want to store the remining checkboxs and textboxs value. I want to store the selected rows checkbox and textbox value.

please help me.... It's very very urgent work..... Kindly help me...
But really i Thanks to this websites. Your tips and idea is very very useful. Again i thanks to this websites.

Regards and Thanks,
Susan
Oct 31 '08 #16
shweta123
692 Expert 512MB
Hi,

Please post the code that you have completed . Also please specify about what output you are getting. So that we can help you in solving your problem.
Oct 31 '08 #17
jhardman
3,406 Expert 2GB
Hello Sir/Madam/Friends!

Please help me. I didn't have experience in asp. i didn't have friend in asp platform. So pls kindly help me...

In one form i have multiple check boxes and textboxes.

for ex:
1 row: "checkbox" Car "textbox" Red color
2 row: "checkbox" Car "textbox" Yellow color
3 row: "checkbox" Bicycle "textbox" Green color
4 row: "checkbox" Scooter "textbox" Red and white color
5 row: "checkbox" Bicycle "textbox" Black color

Now i select 2 checkboxs (1st and 4th).
i want to pass the 1st row checkbox and textbox value (Car, Red color) and 4th row checkbox and textbox value(Scooter, Red and white color) pass into database. How? I didn't want to store the remining checkboxs and textboxs value. I want to store the selected rows checkbox and textbox value.

please help me.... It's very very urgent work..... Kindly help me...
But really i Thanks to this websites. Your tips and idea is very very useful. Again i thanks to this websites.

Regards and Thanks,
Susan
If your inputs were labeled like this:
checkbox1, textbox1, color1
checkbox2, textbox2, color2
etc
I would loop through the request object like this:
Expand|Select|Wrap|Line Numbers
  1. for i = 1 to 5
  2.    if request("checkbox" & i) <> "" then
  3.       'save values in db
  4.    end if
  5. next
For the code about saving the values to the db, check out the howto section, there are a couple articles on saving form input to db. If this gives you trouble, please either post your code and the error it gives, or explain what part is giving you trouble (as shweta asked).

Jared
Oct 31 '08 #18

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

12 posts views Thread by bokke | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.