Scenario: I'm building this html table on the fly and the first column is a checkbox to delete the row. So a user basically checks which rows he/she wants to delete. When they click on the update link it runs this javascript that builds a confirmation string.
I'm looping through the table rows and checking for checked boxes to build this confirmation string. Find below the code I've tried so far. Any help would be appreciated. Questions: 1. How can you use a string variable for the element name when using getElementById?
2. In the code-behind file can you check if the user clicked "ok" or "canceled"?
*****Definition of CheckBox*****
chkboxDel = New HtmlInputCheckBox
With chkboxDel
.Checked = False
.ID = "chkDel" & CStr(i)
End With
*****ServerClick Event for Link*****
if confirmUpdate then
server.transfer("page2")
end if
**********Version 1***********
// This goes through it and does nothing. It doesn't give me a confirmation box.
function confirmUpdate() {
var strMsg = "Do you want to remove the following users from the system:\n\n";
var x = 0;
var strName;
var strLast;
var strFirst;
for (var i=0; i<intRows; i++) {
strName = "chkDel" + i;
if (document.frmMbo.elements[strName].checked) {
strLast = "hidLast" + i;
strFirst = "hidFirst" + i;
strMsg += document.frmMbo.elements[strLast].value + ", " + document.frmMbo.elements[strFirst].value + "\n";
x++;
}
}
if (x > 0) {
if (confirm(strMsg)) {
return true;
}
else {
return false;
}
}
else {
return true;
}
}
**********Version 2************
// This gives me an error saying that the string variable is not defined.
function confirmUpdate() {
var strMsg = "Do you want to remove the following users from the system:\n\n";
var x = 0;
var strName;
var strLast;
var strFirst;
for (var i=0; i<intRows; i++) {
strName = "chkDel" + i;
if (document.getElementById("").checked) {
document.getElementById("").value = "1";
strLast = "hidLast" + i;
strFirst = "hidFirst" + i;
strMsg += document.frmMbo.elements[strLast].value + ", " + document.frmMbo.elements[strFirst].value + "\n";
x++;
}
}
if (x > 0) {
if (confirm(strMsg)) {
return true;
}
else {
return false;
}
}
else {
return true;
}
}
You need to render a client-side array that has all of the checkbox ids. Then, you can iterate through and confirm each row and for each confirmation build up a hidden input containing the confirmed id's to process on PostBack.
try this. instead of getting through loop for checked ids. go through javascript for onclick event of checkbox. get the ids ids into an array/comma sepearted values and then check for confirmation when the delete button is clicked. keep the selected ids in
a hidden variable. when the user confirms to delete then post the page with a new mode as delete and delete the checkedids from by getting from the hidden variable. try this from client side .its quite easy and effecient. any doubts give reply
arivera37
Member
160 Points
32 Posts
CheckBox Question? Need some assistance, please...
Mar 27, 2004 05:07 PM|LINK
*****Definition of CheckBox***** chkboxDel = New HtmlInputCheckBox With chkboxDel .Checked = False .ID = "chkDel" & CStr(i) End With *****ServerClick Event for Link***** if confirmUpdate then server.transfer("page2") end if **********Version 1*********** // This goes through it and does nothing. It doesn't give me a confirmation box. function confirmUpdate() { var strMsg = "Do you want to remove the following users from the system:\n\n"; var x = 0; var strName; var strLast; var strFirst; for (var i=0; i<intRows; i++) { strName = "chkDel" + i; if (document.frmMbo.elements[strName].checked) { strLast = "hidLast" + i; strFirst = "hidFirst" + i; strMsg += document.frmMbo.elements[strLast].value + ", " + document.frmMbo.elements[strFirst].value + "\n"; x++; } } if (x > 0) { if (confirm(strMsg)) { return true; } else { return false; } } else { return true; } } **********Version 2************ // This gives me an error saying that the string variable is not defined. function confirmUpdate() { var strMsg = "Do you want to remove the following users from the system:\n\n"; var x = 0; var strName; var strLast; var strFirst; for (var i=0; i<intRows; i++) { strName = "chkDel" + i; if (document.getElementById("").checked) { document.getElementById("").value = "1"; strLast = "hidLast" + i; strFirst = "hidFirst" + i; strMsg += document.frmMbo.elements[strLast].value + ", " + document.frmMbo.elements[strFirst].value + "\n"; x++; } } if (x > 0) { if (confirm(strMsg)) { return true; } else { return false; } } else { return true; } }Alex
stiletto
All-Star
16995 Points
3304 Posts
Re: CheckBox Question? Need some assistance, please...
Mar 28, 2004 02:37 AM|LINK
umesh chouda...
Member
225 Points
43 Posts
Re: CheckBox Question? Need some assistance, please...
Mar 29, 2004 05:26 AM|LINK