Click to See Complete Forum and Search --> : retrieving values from checkboxes


srimca
04-10-2003, 02:33 AM
i have a form which generates checkboxes dynamically depending upon the database.
how can i assign values each checkbox.
and how to retrieve them and pass on to a java servlet.

let me give u an example;
consider our yahoo mail.
we have rows of messages in inbox.we have a checkbox on each row to enable us to delete a message if we want.
i am developing a similar application.

so howcan thisbe done.
thanx a lot

srimca
04-10-2003, 04:53 AM
anybody with the soln.
iam stuck without it.
thanx

havik
04-10-2003, 09:45 AM
The following does what you want.

Havik

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Test</title>

<script type="text/javascript">

function getvalues() {

var checkbox = document.formname.checkboxname;
var checkboxvalues = new Array();

for(i=0; i < checkbox.length; i++){
checkboxvalues[i] = checkbox[i].value;
alert(checkboxvalues[i]);
}
}

</script>

</head>

<body>

<form name=formname>

<input type=checkbox name=checkboxname value="1">test1
<input type=checkbox name=checkboxname value="2">test2
<input type=checkbox name=checkboxname value="3">test3
<input type=checkbox name=checkboxname value="4">test4
<input type=checkbox name=checkboxname value="5">test5

<input type=submit value=submit onclick="getvalues()">

</form>

</body>
</html>

srimca
04-11-2003, 12:42 AM
thanx havik.some ppl really dont understand.i just pm'ed dave clark telling him that its an urgent question and requested him to help me out.for that he got really annoyed.
who the hell is he to post remarks like that.who has made him the moderator???

thanzx for the reply.
but i need only those values whose checkboxe have been checked.i want to post that object containing these values on to a servlet.

havik
04-11-2003, 08:35 AM
Well, I don't want to take part it any of this so I'm just going to post how to get the values of the checked checkboxes

function getvalues() {

var checkbox = document.formname.checkboxname;
var checkboxvalues = new Array();

var checkboxindex = 0;

for(i=0; i < checkbox.length; i++){

if(checkbox[i].checked == true) {
checkboxvalues[index] = checkbox[i].value;
index++;
}
}
}

checkboxvalues will now have the values of the checked checkboxes.

Havik