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.
17 2674
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!
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 : -
-
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
-
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:
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();
-
}
-
}
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()" >
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:
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..
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.
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()
-
-
%>
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")
-
%>
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
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.....
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
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
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.
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
Sign in to post your reply or Sign up for a free account.
Similar topics
by: teddysnips |
last post by:
Application is a Work Tracking/Timesheet database.
The increments of work are stored in the TimesheetItem table. This
contains, inter alia, the Work Code, the Start and the Duration that
the...
|
by: Jay |
last post by:
I'm trying to build a pretty complex form that submits to an email, but
am having problems with a certain bunch of funcionality in it...
Have a look at this example page......
|
by: Alex Smith |
last post by:
Hi Fiends,
I have made one datagird and then put a one checkbox column on first
columns of grid.
Now i want to
1. if a user select more than two check box than retriving message " please
select...
|
by: bokke |
last post by:
Hi,
I have a page with a link
<a href="Contributor.php?action=&SubCat=<?php echo $row;
?>"><?php echo $row;?></a>
that does to a page with a SELECT
$query = "SELECT * FROM news WHERE...
|
by: Mark |
last post by:
Hey folks, I'm looking at making the following query more efficient
potentially using the ranking functions and I'd like some advice from
the gurus. The purpose of the following is to have a...
|
by: woodey2002 |
last post by:
Hi Guys and thanks for your time.
I have a search form for my database that allows users to select multiple criteria from multi select list boxes.
I successfully integrated a multi select...
|
by: woodey2002 |
last post by:
Hi Everyone. Thanks for your time.
I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option...
|
by: woodey2002 |
last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on.
My databse mostly includes...
|
by: phpnewbie26 |
last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
| |