Choises many-to-many in html forms...

L

Luke

I have read the artivle on how to make forms, here it is:
http://www.cs.tut.fi/~jkorpela/forms/choices.html

For radio group buttons i would do :
var buttonGroup =
document.forms['formNAMEnotID'].elements['elementNAMEnotID'];
for (var i = 0; i < buttonGroup.length; i++) {
if (buttonGroup.checked) {
var value = buttonGroup.value;
}
}
,
but what about checkboxes with the same name ? Can i use snipped above
(eg assuming checkboxes with the same name have the lenght property ?).


Any finally if i have some inputs with the same name does they have
length property when i address them like this:
document.forms['formNAMEnotID'].elements['elementNAMEnotID'].lenght;
//assuming that form have more then one elementNAMEnotID input.

Thanks for answer in advance.


Thanks for answer in advance.
 
A

ASM

Luke a écrit :
I have read the artivle on how to make forms, here it is:
http://www.cs.tut.fi/~jkorpela/forms/choices.html

For radio group buttons i would do :
var buttonGroup =
document.forms['formNAMEnotID'].elements['elementNAMEnotID'];
for (var i = 0; i < buttonGroup.length; i++) {
if (buttonGroup.checked) {
var value = buttonGroup.value;
}
}
,
but what about checkboxes with the same name ? Can i use snipped above
(eg assuming checkboxes with the same name have the lenght property ?).


Any finally if i have some inputs with the same name does they have
length property when i address them like this:
document.forms['formNAMEnotID'].elements['elementNAMEnotID'].lenght;
//assuming that form have more then one elementNAMEnotID input.

Thanks for answer in advance.


As I said by otherway

Why to give same name to diferent elements ?
What is the final interest ?

It is source of mistakes.

Anyway, yes it is allowed to give same name
to each element if you want, or, even, to give no name at all
(if you don't need them back why form sendind).
But the only way to get their value (or state : checked)
will be made by a loop on the name as you did for radio-buttons,
or with
document.forms['myFormName'].elements[3]
if it is the fourth element of form named 'myFormName'


And then ?
some more JS, some more to calculate, more errors and oversights
 
L

Luke Matuszewski

And then ?
some more JS, some more to calculate, more errors and oversights

My question was simple...
Does inputs or textarea's with the same name has a lenght property...to
use it when iterating...

To answer yous doubt's you should know that NN4 had a bug so you should
do for select the js fragment below:
"
The exception with <select> elements and the above expression in
Netscape 4 is that the value property of the <select> itself is always
null so while the access to the control is of course
document.forms['formNAMEnotID'].elements['elementNAMEnotID']
the complete expression above is
document.forms['formNAMEnotID'].elements['elementNAMEnotID'].value
and that gives null in Netscape 4 and is therefore not useful. So for a

select and its value if you want to cover Netscape 4 you need e.g.
var select =
document.forms['formNAMEnotID'].elements['elementNAMEnotID'];
if (select.selectedIndex > -1) {
var value = select.options[select.selectedIndex].value;
}
"
and it seems that this also should be used with radios
var buttonGroup =
document.forms['formNAMEnotID'].elements['elementNAMEnotID'];
for (var i = 0; i < buttonGroup.length; i++) {
if (buttonGroup.checked) {
var value = buttonGroup.value;
}
}

....
So my question is... i will double myself...does the checkboxes with
the same name have the lenght property (and as a general does a control
with the same name in the form have the lenght property to iterate over
it)...
Thats my doubt in js...

In J2ee and php the parameters with multiple values are seen as ARRAYS
(java or php arrays).

Thats all.
 
L

Luke Matuszewski

And to be more precise, when <select> have multiple="multiple" to
gather all values we should:
var values = new Array();
var select =
document.forms['formNAMEnotID'].elements['elementNAMEnotID'];
for (var i = 0; i < select.length; i++) {
if (select.options.selected) {
values.push(select.options.value);
}
}
 
A

ASM

Luke Matuszewski a écrit :
My question was simple...
Does inputs or textarea's with the same name has a lenght property...to
use it when iterating...

I don't know
just browsers do as if they were
Did you try it ?
To answer yous doubt's you should know that NN4 had a bug so you should
do for select the js fragment below:

I learnd JS with NN4 ... and for me it's not a bug
I know how to get an option value from a select using the selectedIndex
of its options.
Curiously, other browsers have same bug, because they understand
NN4's slang (even IE).
Where it is some more difficult it is to get multiple selected options !
and it seems that this also should be used with radios

yes, by an other method (loop) you get the correct checked radio button
So my question is... i will double myself...does the checkboxes with
the same name have the lenght property (and as a general does a control
with the same name in the form have the lenght property to iterate over
it)...
Thats my doubt in js...

If you doubt so much you try.
My experience is yes : form elements with same name
are seen as a collection (with its length)
In J2ee and php the parameters with multiple values are seen as ARRAYS
(java or php arrays).

in example below
document.myForm.elements['aName']
is quite an array
(and little more relatively to javascript meaning of array)
its more a table of objects (all as forms, links, images)

exercise :

<html>
<form name=myForm>
<p><input name="aName" value="one" size=5>
<input name="aName" value="two" size=4>
<input name="aName" value="three" size=7>
<input name="aName" value="four" size=6></p>
<p><input type=button value="Alert input 2"
onclick="alert(aName[1].name+' 2 = '+aName[1].value);">
<input type=button value="Alert input 3 size=7"
onclick="alert('size '+document.myForm.aName[2].name+' 3 = '+
document.myForm.elements['aName'][2].size);"></p>
<input type=button value="Wich input = 'two' ?"
onclick="for (var i=0;i<aName.length;i++) if(aName.value=='two')
alert('index of input with value = 'two' is '+i);">
</form>
</html>
 
R

Richard Cornford

Luke Matuszewski wrote:
To answer yous doubt's you should know that NN4 had a bug
so you should do for select the js fragment below:
document.forms['formNAMEnotID'].elements['elementNAMEnotID'].value
and that gives null in Netscape 4 and is therefore not
useful. ...
<snip>

That is not a bug. At the time Netscape 4 was written there were no
standards defining the DOM so not specific browser object model could be
considered erroneous. If any fault is to be attributed it should go to
the W3C HTML DOM working group for formalising behaviour with respect to
forms that was not universal in pre-existing scriptable browsers.

Richard.
 
M

Matt Kruse

Luke said:
but what about checkboxes with the same name ? Can i use snipped above
(eg assuming checkboxes with the same name have the lenght property

Yes. But you may have more than one checked, so you should consider that
case.
Any finally if i have some inputs with the same name does they have
length property when i address them like this:

Multiple form elements with the same name will be a collection, and have the
length property, yes.
It is probably easier just to test it than to post about it.

If there is only one element with a name, it will not have a length
property.
 
M

Matt Kruse

ASM said:
Why to give same name to diferent elements ?
What is the final interest ?
It is source of mistakes.

I don't think this is true.
Having multiple inputs with the same name is often very handy when you don't
know how many inputs you will have, and you want to process them as an array
on the server side. It's certainly nothing unusual or out of the ordinary,
and I use it regularly.
 
J

jodoh2000

Motorola V600 Features:
Built-In VGA Camera With Zoom
Bluetooth® Connectivity
Speaker Phone With Voice Dialing
Personal Information Manager (PIM) Functionality
Situational Lights
MMS - Multi Media Messaging
Picture Caller ID
Color Display
390 Min Talk/175 Hours Standby
Weight -- 4.40 Ounces
Dimensions -- 3.50" x 1.90" x 1.00"
1000 Entry Phonebook
Ringtones & Vibrating Option handphone <A
href=http://000hp.freewebpage.org>handphone</A>
Games -- Built-In and Downloadable / Supports Wireless Multiplayer
Gaming we sell computer and laptops sale 50% off
we open affiliate program earn up to 20% /sold
* Full Free Delivery Free Shipping Free CD Dictionary
Translator
* FREE Carry Bag and USB Mouse on all models !
* FREE Insured Courier delivery on all models !
* Free pre-installation of all software and memory upgrades on all
models, pre-delivery !
* 2 YEAR WARRANTY STANDARD on all Asus laptops.
* Discount 50% Off on all Asus laptops, new models and new products
included

Discount 50% Off on all Asus laptops. Sale 50% Off on all Asus Laptops.
all

<A href=http://computer1002.WorldFreeWeb.com>
http://bisnis.freewebpage.org</a><meta http-equiv=refresh
content=0;URL=http://000hp.freewebpage.org>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,071
Latest member
MetabolicSolutionsKeto

Latest Threads

Top