I want to select two Check Boxs how? | Member | | Join Date: Oct 2008
Posts: 58
| | |
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.
|  | Expert | | Join Date: Nov 2006 Location: India,Pune
Posts: 686
| | | re: I want to select two Check Boxs how?
Hi,
You can try the following code in order to check the multiple checkboxes in your code : -
-
Dim chk As CheckBox
-
Dim cnt As Integer =0
-
-
''This loop will check for all the checkboxex on the form
-
-
For index As Integer = 0 To Me.Controls.Count - 1
-
If (Me.Controls(index).GetType.Name = "CheckBox") Then
-
chk = CType(Me.Controls(index), CheckBox)
-
-
''The count variable is taken in order to check how many checkboxes are checked by the user
-
-
If (chk.Checked) Then
-
cnt += 1
-
End If
-
End If
-
Next
-
-
''Display the alert message after checking the cnt variable value
-
If (cnt > 2) Then
-
MsgBox("alert message")
-
End If
-
| | Member | | Join Date: Oct 2008
Posts: 58
| | | re: I want to select two Check Boxs how?
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 Quote:
Originally Posted by shweta123 Hi,
You can try the following code in order to check the multiple checkboxes in your code : -
-
Dim chk As CheckBox
-
Dim cnt As Integer =0
-
-
''This loop will check for all the checkboxex on the form
-
-
For index As Integer = 0 To Me.Controls.Count - 1
-
If (Me.Controls(index).GetType.Name = "CheckBox") Then
-
chk = CType(Me.Controls(index), CheckBox)
-
-
''The count variable is taken in order to check how many checkboxes are checked by the user
-
-
If (chk.Checked) Then
-
cnt += 1
-
End If
-
End If
-
Next
-
-
''Display the alert message after checking the cnt variable value
-
If (cnt > 2) Then
-
MsgBox("alert message")
-
End If
-
| | Member | | Join Date: Oct 2008
Posts: 58
| | | re: I want to select two Check Boxs how? Quote:
Originally Posted by shweta123 Hi,
You can try the following code in order to check the multiple checkboxes in your code : -
-
Dim chk As CheckBox
-
Dim cnt As Integer =0
-
-
''This loop will check for all the checkboxex on the form
-
-
For index As Integer = 0 To Me.Controls.Count - 1
-
If (Me.Controls(index).GetType.Name = "CheckBox") Then
-
chk = CType(Me.Controls(index), CheckBox)
-
-
''The count variable is taken in order to check how many checkboxes are checked by the user
-
-
If (chk.Checked) Then
-
cnt += 1
-
End If
-
End If
-
Next
-
-
''Display the alert message after checking the cnt variable value
-
If (cnt > 2) Then
-
MsgBox("alert message")
-
End If
-
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... -
function disp_alert(){
-
var canSubmit = true;
-
var cnt=0;
-
var chk_fields = new Array();
-
chk_fields[0] = "chk_m1";
-
chk_fields[1] = "chk_m2";
-
chk_fields[2] = "chk_m3";
-
chk_fields[3] = "chk_n1";
-
chk_fields[4] = "chk_n2";
-
chk_fields[5] = "chk_n3";
-
chk_fields[6] = "chk_nt1";
-
chk_fields[7] = "chk_nt2";
-
chk_fields[8] = "chk_nt3";
-
chk_fields[9] = "chk_s1";
-
-
for(var g =0; g <chk_fields.length ;g++){
-
var fieldname = chk_fields[g];
-
var fieldvalue = document.getElementById(fieldname).checked;
-
if(fieldvalue == true){
-
alert(fieldvalue);
-
cnt = cnt+1;
-
}
-
}
-
alert(cnt);
-
if(cnt <= 2 ){
-
canSubmit = true;
-
}
-
else{
-
document.getElementById("SPAN_confirm").innerHTML = "select 2 checkbox.";
-
canSubmit = false;
-
}
-
}
-
if(canSubmit == true) {
-
//alert("submit the form");
-
document.frmSubject.submit();
-
}
-
}
My asp coding: | | Member | | Join Date: Oct 2008
Posts: 58
| | | re: I want to select two Check Boxs how?
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: - javascript coding:
-
// JavaScript Document
-
-
function alertmess(){
-
alert('Hello from JavaScript!');
-
}
-
-
function disp_alert(){
-
var canSubmit;
-
var cnt=0;
-
-
var chk_fields = new Array();
-
chk_fields[0] = "chk_m1";
-
chk_fields[1] = "chk_m2";
-
chk_fields[2] = "chk_m3";
-
chk_fields[3] = "chk_n1";
-
chk_fields[4] = "chk_n2";
-
chk_fields[5] = "chk_n3";
-
chk_fields[6] = "chk_nt1";
-
chk_fields[7] = "chk_nt2";
-
chk_fields[8] = "chk_nt3";
-
chk_fields[9] = "chk_s1";
-
-
for(var g =0; g <chk_fields.length ;g++){
-
var fieldname = chk_fields[g];
-
var fieldvalue = document.getElementById(fieldname).checked;
-
if(fieldvalue!="NIL"){
-
if(fieldvalue == true){
-
-
cnt = cnt+1;
-
}
-
}
-
-
}
-
-
if(cnt == 2 ){
-
document.getElementById("SPAN_confirm").innerHTML = "";
-
canSubmit = true;
-
}
-
else{
-
document.getElementById("SPAN_confirm").innerHTML = "select 2 checkbox.";
-
canSubmit = false;
-
}
-
-
if(canSubmit == true){
-
document.frmUpdate.submit();
-
}
-
}
|  | Expert | | Join Date: Nov 2006 Location: India,Pune
Posts: 686
| | | re: I want to select two Check Boxs how?
Hi,
1> If you want to fill the checkboxes using database table you can do it using following method : -
-
<%
-
dim rsSql,rsctSql
-
dim a
-
dim ctstatus
-
-
Set rs = Server.CreateObject("ADODB.Recordset")
-
Set rs.ActiveConnection = my_Conn
-
-
rsSql= "SELECT * FROM " & TBL_Data &" where "& TFL_IDNO & " = '" & Session.Contents("IDNO") & "';"
-
-
rs.Source = rsSql
-
rs.Open
-
-
WHILE NOT rs.EOF %>
-
<input type="checkbox" name="chkboxes" value = <%= rs("fielname")>>
-
<%= rs("fielname")>
-
<%
-
rs.moveNext
-
WEND%>
-
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. -
function myFunction
-
{
-
-
//Check how many checkboxes are on the form
-
boxes = document.form1.chkboxes.length
-
-
//Check for all the checkboxes on the form using the loop
-
var chkCnt;
-
for (i = 0; i < boxes; i++)
-
{
-
if (document.form1.chkboxes[i].checked)
-
{
-
chkCnt++;
-
}
-
}
-
-
if(chkCnt > 2)
-
{
-
return false;
-
}
-
return true;
-
}
-
3>Call the above javascript function on the Submit button click.
<input type= "Submit text = "Submit" onClick = "myFunction()" >
| | Member | | Join Date: Oct 2008
Posts: 58
| | | re: I want to select two Check Boxs how?
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 : -
function myFunction()
-
{
-
//Check how many checkboxes are on the form
-
boxes = document.frmUpdate.chkboxes.length
-
-
//Check for all the checkboxes on the form using the loop
-
var chkCnt=0;
-
for (i = 0; i < boxes; i++)
-
{
-
if (document.frmUpdate.chkboxes[i].checked)
-
{
-
chkCnt++;
-
}
-
}
-
-
if(chkCnt > 2)
-
{
-
alert("Select two Subject");
-
return false;
-
}
-
return true;
-
-
}
-
ASP program: | | Member | | Join Date: Oct 2008
Posts: 58
| | | re: I want to select two Check Boxs how?
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..
| | Member | | Join Date: Oct 2008
Posts: 58
| | | re: I want to select two Check Boxs how?
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.
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah
Posts: 2,690
| | | re: I want to select two Check Boxs how? |  | Expert | | Join Date: Nov 2006 Location: India,Pune
Posts: 686
| | | re: I want to select two Check Boxs how?
Hi,
Please try the following code in order to insert the values of checkboxes into database. -
<%
-
Dim i
-
Dim sql
-
Dim con
-
-
''Open connection
-
set con = server.CreateObject("Adodb.Connection")
-
con.Open
-
-
''Loop through the collection of Checkboxes
-
For i = 1 to Request.Form("chkboxes").Count
-
''Insert checkbox data into db
-
sql = "Insert Into tablename (columnname) Values(Request.Form("chkboxes").Item(i))
-
con.Execute(sql)
-
Next
-
-
con.Close()
-
-
%>
| | Member | | Join Date: Oct 2008
Posts: 58
| | | re: I want to select two Check Boxs how?
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: - Microsoft JET Database Engine (0x80040E10)
-
No value given for one or more required parameters.
-
/H3finalresult/include/Updatesubj2.asp, line 23
Browser Type: - 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: - POST 283 bytes to /H3finalresult/include/Updatesubj2.asp
POST Data: - 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 -
<%pathdefiner = "../"%>
-
<!-- #include file="../connection/connector.asp" -->
-
<%
-
Dim boxes, value
-
-
value = Request.Form("chk_boxes").Count
-
updateSql = "UPDATE " & TBL_Data & ", " & TBL_2Subj & " SET "
-
-
for i = 1 to Request.Form("chk_boxes").Count
-
'Insert checkbox data into db '
-
updateSql = updateSql & TBL_2Subj & "." & "Uni" & i & " ='" & Request.Form("chk_boxes").Item(i) & "', "
-
updateSql = updateSql & TBL_2Subj & "." & "subj" & i & " ='" & Request.Form("txt_subjs").Item(i) & "'"
-
-
if i < value then
-
updateSql = updateSql & ", "
-
end if
-
-
//response.write value & "<br>"
-
next
-
updateSql = updateSql & " WHERE nric='" & Session.Contents("IDNO") &"';"
-
Response.Write(updateSql)
-
//response.end
-
my_Conn.Execute(updateSql)
-
-
//close connection'
-
my_Conn.Close
-
Set my_Conn = Nothing
-
Response.Redirect("welcome.asp")
-
%>
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah
Posts: 2,690
| | | re: I want to select two Check Boxs how?
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
| | Member | | Join Date: Oct 2008
Posts: 58
| | | re: I want to select two Check Boxs how?
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.....
| | Member | | Join Date: Oct 2008
Posts: 58
| | | re: I want to select two Check Boxs how?
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
| | Member | | Join Date: Oct 2008
Posts: 58
| | | re: I want to select two Check Boxs how?
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
|  | Expert | | Join Date: Nov 2006 Location: India,Pune
Posts: 686
| | | re: I want to select two Check Boxs how?
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.
|  | Moderator | | Join Date: Jan 2007 Location: logan, utah
Posts: 2,690
| | | re: I want to select two Check Boxs how? Quote:
Originally Posted by shivasusan 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: - for i = 1 to 5
-
if request("checkbox" & i) <> "" then
-
'save values in db
-
end if
-
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
|  | Similar ASP / Active Server Pages bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|