473,387 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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

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[i].checked) {
var value = buttonGroup[i].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.

Sep 25 '05 #1
8 2001
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[i].checked) {
var value = buttonGroup[i].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

--
Stephane Moriaux et son [moins] vieux Mac
Sep 25 '05 #2

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[i].checked) {
var value = buttonGroup[i].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.

Sep 25 '05 #3
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[i].selected) {
values.push(select.options[i].value);
}
}

Sep 25 '05 #4
ASM
Luke Matuszewski a écrit :
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...


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[i].value=='two')
alert('index of input with value = 'two' is '+i);">
</form>
</html>


--
Stephane Moriaux et son [moins] vieux Mac
Sep 25 '05 #5
Luke Matuszewski wrote:
<snip>
To answer yous doubt's you should know that NN4 had a bug
so you should do for select the js fragment below: <snip> 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.
Sep 25 '05 #6
Luke wrote:
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.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 26 '05 #7
ASM wrote:
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.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Sep 26 '05 #8
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>

Sep 26 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Miriam | last post by:
Is it possible to disable a form control (eg. text box) without affecting it's foreground and background colors (I want it to look the same, but disallow user input. Miriam
3
by: mark | last post by:
about the configuration manager's platform listbox. The choises are: ..NET and ACTIVE(.NET) What's this about? I can't find it anywhere in the online help. -- mark
23
ADezii
by: ADezii | last post by:
Many Access Users fail to realize that it has a built-in Progress Meter that can display the relative completion percentage of various processes. It is fairly limited, but nonetheless, does provide...
27
by: Wernerh | last post by:
Please could anyone tell me what is wrong with this code. Do I need anything else other than this for it to work, or is my code missing further info requirements. Presently getting no result in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.