Reputation:
I am very new to JSP and I have the following issue:
I have to get the values of checkboxes that are checked and make use of these values in Java
In my approve.jsp I have a function called validateApprove() which is called when a button is clicked.
function validateApprove() {
var cc= document.getElementsByName('imagecheckbox');
var j=0;
var values = new array();
for (var i = 0; i < cc.length; i++) {
if(cc[i].checked == true) {
values[j]== cc[i].value;
j++;
}
}
if (j==0) {
alert("please check atleast one item");
} else {
alert("Are you sure? Do you want to approve " + j + " item(s)");
}
}
the error I get is: ReferenceError: array is not defined
Why is that error thrown? Can I use array in Java like the following way:
String vals[] = request.getParameterValues("values");
Upvotes: 0
Views: 117
Reputation: 25
function validateApprove() {
var cc=[];
var temp = document.getElementsByName('imagecheckbox');
cc.push(temp);
var j=0;
var values = new Array();
for (var i = 0; i < cc.length; i++) {
if(cc[i].checked == true) {
values[j]== cc[i].value;
j++;
}
}
if (j==0) {
alert("please check atleast one item");
} else {
alert("Are you sure? Do you want to approve " + j + " item(s)");
}
}
enter code here
Upvotes: 0
Reputation: 12993
Mistake in
var values = new array();
Should be
var values = new Array();
A
not a
in array declaration.
Upvotes: 1