English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

2007-03-07 02:33:06 · 5 answers · asked by Ramora Desoleb 2 in Computers & Internet Programming & Design

I'm sorry my questions a bit fuzzy,. Anyways i have this while loop, everytime the loop enters a checkbox is made and depending on the result set i get, i append this to the name of the checkbox. My problem now is how to i get these values on the next page, not knowing how many checkboxes there are and their names? I go to the next page by the submit button, it's a form. Any ideas?

2007-03-07 02:40:56 · update #1

5 answers

In the HTML DOM, checkboxes with the same name are returned as an array. If the box is checked, then its selected property is true; if not, it is false.

You somehow managed to not indicate what language you are using, so I will provide three examples of how to determine if a checkbox with the same name is selected.

In ASP.NET, you use the CheckBoxList class; specifically, the Items.Selected property, to determine if a given checkbox is selected. Let's suppose you have a checkboxlist named myCheckboxes:

For I = 0 To myCheckboxes.Items.Count -1
If myCheckboxes.Items(I).Selected Then
Response.Write( myCheckboxes.Items(I).Value & "
" )
End If
Next

In PHP, you can use the $_POST or $_GET superglobals, but you need to indicate, in your form elements, that each item in the check box list will be part of an array, e.g.:





Only the items that have actually been checked will be part of the array.

I find it easiest to assign the array that will be returned by the superglobal to a new array variable, then work with that:

$myarray = $_POST['box'];
foreach($myarray as $item) {
echo "$item
";
}
?>

In JavaScript / DOM, you use the getElementsByName property to get all the items in a checkbox array, and then iterate through them, looking for checked items. I have several examples of this on my blog; try this one:

http://www.dougv.com/blog/2007/01/09/displaying-a-new-image-based-on-image-choices-via-checkboxes-the-html-dom-and-javascript/

2007-03-07 03:21:09 · answer #1 · answered by Anonymous · 0 0

You need to set up a counter so that every time a checkbox is added, the counter is incremented by one.

As for the checkbox names, you can create an array to track them or just append to a string, like:

strNames = strNames & ", " & checkBox2Name

So when you pass the string to the next form, it would read something like:

chkBox1name, chkBox2name, chkBox3name, etc...

hope that helps

2007-03-07 03:01:16 · answer #2 · answered by rod 6 · 0 1

Maintain the counter as a var (gotta be stored *somewhere*! Is your form handler the server? Then there! Else as a cookie on the client.) Then use that var to name the checkbox field name as in "checkbox_var" and use your code to "parse it out" as in fieldname="check_" + string(var) so that fieldname comes out as "check_1" or "check_2" "check_3" etc.

2007-03-07 04:21:39 · answer #3 · answered by fjpoblam 7 · 0 0

ISSET contained in relation to checkboxes will basically return authentic if the field is checked in contrast to textual content cloth or drop downs. If not checked, you will get a pretend. So in many situations for checkboxes, you will not even use isset() to validate. If the checkbox is checked, you will get a value, so which you will could desire to be responsive to the call of the checkbox field. in case you generate the checkboxes in a loop, evaluate naming them with brackets so as that Hypertext Preprocessor will comprehend them as an array.

$var2 = $_POST['var2']; foreach($var2 as $v){ echo $v."-"; } anticipate that each and all and sundry values have been checked, you will get an output of "on-2-3-". provided that between the values replaced into not declared, an "on" value is right now assigned.

2016-10-17 11:48:33 · answer #4 · answered by Anonymous · 0 0

If checkbox.value = 1: then it is checked
if checkbox.value = true: then it is checked
if checkbox.value = 0: then the checkbox is unchecked
if checkbox.value = false: then the checkbox is unchecked

2007-03-07 02:38:24 · answer #5 · answered by thesatsui 3 · 0 1

fedest.com, questions and answers