Click to See Complete Forum and Search --> : Form element


RJ2003
04-17-2003, 10:30 AM
I have a form containing :
1) 2 radio button options, one of them is "ALL".

2) A table with 3 columns.
Columns are :
1) Include - checkbox
2) Dealer Name - hard coded text
3) Url - text box

What I want to do is, if a user selects "ALL" radio button, then all checkboxes in the table are checked. Just like in an inbox of hotmail or yahoo where you select "Delete All" checkbox and it check marks all the emails.

Thanks,
RJ

gil davis
04-17-2003, 11:22 AM
<script>
function checkall(it) {
for (var i=0; i<=it.length; i++)
{it[i].checked = true;}
}
function clearall(it) {
for (var i=0; i<=it.length; i++)
{it[i].checked = false;}
}
</script>
<form name="f1" onSubmit="return false">
<input type="radio" name="r1" value="yes" onclick="if(this.checked){checkall(this.form.c1)}">Check All<br>
<input type="radio" name="r1" value="no" onclick="if(this.checked){clearall(this.form.c1)}">Clear All<br>
<input type="checkbox" name="c1" value="1"><br>
<input type="checkbox" name="c1" value="2"><br>
<input type="checkbox" name="c1" value="3"><br>
<input type="checkbox" name="c1" value="4"><br>
<input type="checkbox" name="c1" value="5"><br>
<input type="checkbox" name="c1" value="6">
</form>

RJ2003
04-22-2003, 08:54 AM
Thanks.

Refering to the solution suggested above, if I check only 3 out of 6 checkbox (all by the name=c1), how can i retrieve their values ?
Remeber, they all have same name=c1.

gil davis
04-22-2003, 09:33 AM
how can i retrieve their values ?You step through them using a for loop and get their value. Since you didn't indicate what you intend to do with it, I don't know what else to tell you. I suppose you could concatenate all the values.function getValues(it) {
var val = "";
for (var i=0; i<=it.length; i++)
{if (it[i].checked) val += it[i].value;}
return val;
}

havik
04-22-2003, 09:48 AM
Or you could put it into an array,

var values = new Array();

function getValues(it) {
valuesindex = 0;
for (var i=0; i<=it.length; i++) {
if (it[i].checked) {
values[valuesindex] = it[i].value;
valuesindex++;
}
}
}

Havik

Jona
04-22-2003, 10:28 AM
For your information, setting the property checked to true does not check the box as expected. You must use return true. See: http://forums.webdeveloper.com/showthread.php?s=&threadid=8207

RJ2003
04-24-2003, 06:05 AM
its not working out.
Let me explain in a better way.

I have a form in a jsp with :
2 radio buttons - "List All" AND "List only with with check mark"

Then below this is a table with 3 rows -
"Include" - checkbox
some text - label
user input - textbox

What I want is when the user selects "List All" radio button, all the checkboxes of all rows in the tables should be check marked.
PLS NOTE - my checkbox names are - checkbox1, checkbox2,....checkbox80.

Also, when this form is submitted, it goes to another jsp. This jsp should retieve all values checked. How can i retieve the values ? If I name all checkboss differently (as I am doing), i can use request.getParameter("checkbox10")...but if I name them same, how can I get their values in the next jsp ?

tam42025
04-24-2003, 08:03 AM
Hi all, I have a similiar problem. I have dropdown menus, and two text boxes that allow my users to input information to search when they hit submit. I too don't know how to get my code to recognize that I want all of those selections to be included in the search and if they just select only some of the options to still search for whatever they select together. I am trying my best to create a "advanced search" and I was wondering if what you replied above will get me to were I am going too.

Thanks

RJ2003
04-24-2003, 08:36 AM
tam42025, you should have actually posted this in a separate thread. I just hope ppl are now not confused about MY problem.

tam42025
04-24-2003, 08:40 AM
I apologize but I was not trying to make things more confusing for you. I thought our problems were very similiar and that if what they suggested would be a good solution for you would it also work for me.

Once again, I apologize. I have been working on my script for a month and I am still no closer to a solution. They are extremely helpful on this board, I guest I just don't get what I am being told. lol

RJ2003
04-24-2003, 11:19 AM
Anybody ????

gil davis
04-24-2003, 11:42 AM
Let me explain in a better way ... my checkbox names are - checkbox1, checkbox2,....checkbox80
<script>
function checkall(it, len) {
for (var i=1; i<=len; i++)
{it["checkbox" + i].checked = true;}
}
function clearall(it, len) {
for (var i=1; i<=len; i++)
{it["checkbox" + i].checked = false;}
}
</script>
...
<input type="radio" name="r1" value="yes" onclick="if(this.checked){checkall(this.form, 80)}">Check All<br>
<input type="radio" name="r1" value="no" onclick="if(this.checked){clearall(this.form, 80)}">Clear All<br>
...The submit action should give you each box checked automatically.