form elements with the same name
Moderator: General Moderators
-
jessevitrone
- Forum Newbie
- Posts: 15
- Joined: Tue Aug 12, 2003 2:42 pm
form elements with the same name
I have a form with a group of checkboxes, all with the same name. I'm generating the list of checkboxes, so I don't know how many there are.
I also deal with Java, and using servlets I can get the parameter for the form element and it returns me an array, since there was than one element with the same name.
Does PHP do that? I only seem to be getting back the last element when I check $_POST["elementName"]; I would've thought it would give me back an array, like Java does. Am I missing something? Or does PHP restrict you and only return the value from the last element with that name?
Thanks in advance,
Jesse
I also deal with Java, and using servlets I can get the parameter for the form element and it returns me an array, since there was than one element with the same name.
Does PHP do that? I only seem to be getting back the last element when I check $_POST["elementName"]; I would've thought it would give me back an array, like Java does. Am I missing something? Or does PHP restrict you and only return the value from the last element with that name?
Thanks in advance,
Jesse
Example:
Code: Select all
<input type="checkbox" name="fooї]">
<input type="checkbox" name="fooї]">
<input type="checkbox" name="fooї]">
<input type="checkbox" name="fooї]">-
jessevitrone
- Forum Newbie
- Posts: 15
- Joined: Tue Aug 12, 2003 2:42 pm
JAM
Ah.....just what I was looking for. Thanks.
-
jessevitrone
- Forum Newbie
- Posts: 15
- Joined: Tue Aug 12, 2003 2:42 pm
javascript problem with using [] notation
If my form element name is now "elementName[]", how can I refer to it with Javascript?
When I try document.forms.myform.elementName[], it's a syntax error. I tried getting it with eval("document.forms.myform.elementName[]") too, but that didn't help.
Any suggestions?
Thanks.
When I try document.forms.myform.elementName[], it's a syntax error. I tried getting it with eval("document.forms.myform.elementName[]") too, but that didn't help.
Any suggestions?
Thanks.
Code: Select all
// short examples...
$elementNameї] = 'foo';
$elementNameї] = 'bar';
echo 'document.forms.myform.' . $elementNameї0];
echo 'document.forms.myform.' . $elementNameї1];
/* Results:
document.forms.myform.foo
document.forms.myform.bar
*/- Seth_[php.pl]
- Forum Commoner
- Posts: 30
- Joined: Sun Aug 10, 2003 5:25 am
- Location: Warsaw / Poland
-
jessevitrone
- Forum Newbie
- Posts: 15
- Joined: Tue Aug 12, 2003 2:42 pm
solution
I was able to do it with this:
This only works because I never try to refer to the field by name.
It does what I need it to do for now, hopefully I won't run into a case where I have to get it by name.
Code: Select all
var elements = document.forms.publishForm.elements;
for (var i = 0; i < elements.length; i++) {
if (elementsїi].type == "checkbox") {
elementsїi].checked = true;
}
}It does what I need it to do for now, hopefully I won't run into a case where I have to get it by name.