PDA

View Full Version : uncheck all check boxes


Jason
03-05-2003, 11:36 PM
does anyone have a simple uncheck all checkboxes code snippet? I have a bunch of dynamically created check boxes and I have a button that will "uncheck" all of them with it. Any suggestions?

Jason

cheesebagpipe
03-06-2003, 12:18 AM
function uncheckem(oForm) {
var formLength = oForm.length;
for (var e=0; e<formLength; ++e)
if (oForm.elements[e].type == 'checkbox')
oForm.elements[e].checked = false;
}

<input type="button" value="Uncheck All" onclick="uncheckem(this.form)">

Jason
03-06-2003, 12:34 AM
I don't really understand all those calls or what thats really supposed to do but I cut and pasted it anyway and it didn't work. Any other suggestions?

Jason

cheesebagpipe
03-06-2003, 12:37 AM
Is the button in the same form as the checkboxes?

Other suggestion: post some code....:rolleyes:

Jason
03-06-2003, 12:43 AM
technically it nost a form...here is the call I use to make the check boxes on the web page, its really a popup window with only checkboxes on it.

echo "<INPUT TYPE=\"checkbox\" NAME=\"off_hrs_time\" VALUE=\"y\" "
. (($ver_ans == 1)?"CHECKED":"UNCHECKED") . "> " . "$display_time";
?><BR><?php

Oh, and Im using PHP if you haven't noticed, this is run through a for loop and created a number of checkboxes in a colum.


Jason

cheesebagpipe
03-06-2003, 01:04 AM
Well...technically make it a form; just put the usual <form></form> tags around all the form elements. You won't get a Form object without it, and the script won't have an elements[] array to look through. You should always use at least a skeleton web page in a popup (or any window); browsers will usually attempt to display disconnected elements properly, but there's virtually no penalty for doing it the right way.

Jason
03-06-2003, 01:08 AM
hahahaha, crappy that damn <form> </form> made it work. Thanks

I also modified that code alittle so that it would "check" all the boxes too.

Jason

Jason
03-06-2003, 01:21 AM
one more quick question that relates to this. I am going to have another button, say a submit button. I want it to post the values of those that are checked when it is clicked. How do i do that?

Jason

cheesebagpipe
03-06-2003, 01:52 AM
You want to post the name/value pairs of a series of checkboxes to the server when a HTML form is submitted? That's the most outrageous thing I've ever heard!

:D OK...give the individual boxes individual names & values in your PHP, relating to whatever it is they represent. And...no such HTML attribute as 'UNCHECKED'.

Jason
03-06-2003, 09:50 PM
actually I am trying to find out that info so that I can insert the name and values into a DB using the php and postgres scripts I wrote.

Jason