It is well-documented that if on a page there are several radio-
buttons with the same name these are addressed as an array (and act
collectively).
Someone (LRN?) recently wrote about another case where name-match
implies array addressing.
It therefore occurred to me to try the following crude Web page :
<head></head><body>
<form name=F1>
<input type=text name=A size=3 value=00>
<input type=text name=A size=3 value=11>
<input type=text name=A size=3 value=22>
<input type=button name=B onClick=X() value=" ?? ">
</form>
<script>
J=0
function X() {
F1.B.value = " " + F1.A[J++%3].value + " "
}
</script>
</body>
On it, in my MSIE4, pressing the ?? button repeatedly cycles its
legend through 00 11 22 00 11 22 00 ... which demonstrates that such
a set of name-matched controls can be accessed as an array there.
Is that legitimate and generally available? I do not recall reading
it.
In particular, where I have a table similar in principle to
2001 2002 2003 2004 2005
St P Sat Sun Mon Wed Thu
St G Mon Tue Wed Fri Sat
St A Fri Sat Sun Tue Wed
and wish to auto-change the columns to be Year-2..Year+2 for any
(current) Year, can I use for the St P row five instances of
<input type=text name=StP size=5 readonly> and compute in turn
elements [0]..[4] of this array (likewise for other rows), and have
it working successfully for all reasonable javascript-enabled
browsers?
Could I use <div>..</div> with DynWrite thus, instead of <input
....>?
I postpone the possibility of having a dynamic column-count such
that there is at least one instance of each of the days of the week
in both the row for Feb 28 and that for Mar 1.
--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
<URL:http://www.merlyn.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links. 17 2797
Dr John Stockton wrote on 27 Nov 2003:
<snip> <input type=button name=B onClick=X() value=" ?? ">
Omission of the quotes around the onclick attribute value may have
been intentional, but I would like to point out that the only non-
alphanumeric characters that may appear in an unquoted attribute
value are hyphens, periods, underscores and colons.
<snip>
On it, in my MSIE4, pressing the ?? button repeatedly cycles its legend through 00 11 22 00 11 22 00 ... which demonstrates that such a set of name-matched controls can be accessed as an array there.
Is that legitimate and generally available? I do not recall reading it.
Netscape's JavaScript reference (v1.3) states in the introduction for
the Radio object that a group of radio buttons under the same name
may be indexed with subscripts. In addition, the DOM method,
getElementsByNa me, will return "the (possibly empty) collection of
elements whose name value is given" in the argument to the method.
In particular, where I have a table similar in principle to
2001 2002 2003 2004 2005 St P Sat Sun Mon Wed Thu St G Mon Tue Wed Fri Sat St A Fri Sat Sun Tue Wed
and wish to auto-change the columns to be Year-2..Year+2 for any (current) Year, can I use for the St P row five instances of <input type=text name=StP size=5 readonly> and compute in turn elements [0]..[4] of this array (likewise for other rows), and have it working successfully for all reasonable javascript-enabled browsers?
Only INPUTs of type radio and checkbox can share control names. A
solution would be to use an array that contained the names of each
text box, index that, and use the value with the elements property of
a Form object or, if they are id values, as the argument to the
getElementById method.
Could I use <div>..</div> with DynWrite thus, instead of <input ...>?
If you are referring to dynamically altering an already loaded page,
I wouldn't know. If not, could you explain what you mean here?
Mike
--
Michael Winter M.******@blueyo nder.co.uk.invalid (remove ".invalid" to reply)
Dr John Stockton <sp**@merlyn.de mon.co.uk> writes: It is well-documented that if on a page there are several radio- buttons with the same name these are addressed as an array (and act collectively).
Someone (LRN?) recently wrote about another case where name-match implies array addressing.
Probably. It works that way for all form controls. Try:
<form id="foo">
<input type="text" name="x" value="42">
<input type="radio" name="x" value="37">
<input type="checkbox" name="x" value="87">
<select name="x"><optio n value="13" selected="selec ted">X</option></select>
</form>
<script type="text/javascript">
var xs = document.forms['foo'].elements['x'];
alert([xs.length,xs[0].value,xs[1].value,xs[2].value,xs[3].value]);
</script>
It alerts
4,42,47,87,13
in IE6, Opera 7, and Mozilla (and with some rewriting also in Netsape 4).
J=0
function X() { F1.B.value = " " + F1.A[J++%3].value + " " }
On it, in my MSIE4, pressing the ?? button repeatedly cycles its legend through 00 11 22 00 11 22 00 ... which demonstrates that such a set of name-matched controls can be accessed as an array there.
It's not an array. If you check with "... instanseof Array", it gives
false. In Opera, it's an Object. In Mozilla, it's a NodeList. The
important thing is that it doesn't have a dynamic length or the methods
of Array.prototype .
Is that legitimate and generally available?
Apart from writing
F.B.value
instead of
document.forms. F.elements.B.va lue
then yes. (It wouldn't work in Mozilla using F as a global variable)
I do not recall reading it.
I can't find it in the DOM specification.
The HTMLFormDocumen t's "elements" property is a HTMLCollection.
Its "namedItem" method is only allowed to return a single Node.
It is probably a result of the DOM specification being written
to be compatible with typed languages, so the "namedItem" method
can't return a Node in some cases and a NodeList in others (NodeList
is what is returned by, e.g., getElementsByTa gName)
So, you'll have to look at the browser specific DOMs to find anything.
in Microsoft's documentation, you find:
---
If this parameter is a string and there is more than one element
with the name or id property equal to the string, the method returns
a collection of matching elements.
---
There is problably something similar in a Netscape documentation.
In particular, where I have a table similar in principle to
2001 2002 2003 2004 2005 St P Sat Sun Mon Wed Thu St G Mon Tue Wed Fri Sat St A Fri Sat Sun Tue Wed
and wish to auto-change the columns to be Year-2..Year+2 for any (current) Year, can I use for the St P row five instances of <input type=text name=StP size=5 readonly> and compute in turn elements [0]..[4] of this array (likewise for other rows), and have it working successfully for all reasonable javascript-enabled browsers?
It should work. But if you have a table with a known width/height, you
can just name the elements based on the coordinates, e.g.
name="St(2,3)"
Could I use <div>..</div> with DynWrite thus, instead of <input ...>?
Not generally, no. There is no "name" attribute on a div, and the
"id" attribute must be unique. In IE, you can have several elements
with the same id, and document.all/document.getEle mentById will
return a collection. That is not portable.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Michael Winter <M.******@bluey onder.co.uk.inv alid> writes: Only INPUTs of type radio and checkbox can share control names.
Reference? I see no such restriction in the HTML 4.01 specification.
It does *hint* it:
---
Several checkboxes in a form may share the same control name.
---
and
---
Radio buttons are like checkboxes except that when several share the
same control name, they are mutually exclusive
---
No other control has its name mentioned.
perhaps it is what they mean by
---
The scope of the name attribute for a control within a FORM element
is the FORM element.
---
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Lasse Reichstein Nielsen wrote on 27 Nov 2003: Michael Winter <M.******@bluey onder.co.uk.inv alid> writes:
Only INPUTs of type radio and checkbox can share control names.
Reference? I see no such restriction in the HTML 4.01 specification.
It does *hint* it: --- Several checkboxes in a form may share the same control name. --- and --- Radio buttons are like checkboxes except that when several share the same control name, they are mutually exclusive --- No other control has its name mentioned. perhaps it is what they mean by --- The scope of the name attribute for a control within a FORM element is the FORM element. ---
Two controls in different forms can use the same name, but what Dr
Stockton wanted to do was use several text boxes with the same name
in the same form, which you cannot do. My statement was meant in the
context of his query, though I suppose I should have written:
Only INPUTs of type radio and checkbox can share control names within
the same form.
I knew the distinction, but I didn't feel it merited mentioning. I
was wrong.
Mike
--
Michael Winter M.******@blueyo nder.co.uk.invalid (remove ".invalid" to reply)
Michael Winter <M.******@bluey onder.co.uk.inv alid> writes: Two controls in different forms can use the same name, but what Dr Stockton wanted to do was use several text boxes with the same name in the same form, which you cannot do.
That is what I was asking for a reference for. I can't find that
restriction in the HTML specification.
My statement was meant in the context of his query, though I suppose I should have written:
Only INPUTs of type radio and checkbox can share control names within the same form.
That's how I read it. There is no explicit requirement in HTML that
control names must be distinct, and no browser that I have available
have a problem with several controls with the same name. The resulting
URL is "...?x=XXX&x=YY Y&x=ZZZ".
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Lasse Reichstein Nielsen wrote on 27 Nov 2003: Reference? I see no such restriction in the HTML 4.01 specification.
It does *hint* it:
No other control has its name mentioned.
In my previous response, I didn't think properly about the above
statements. You are correct - there is no restriction stating that
control names must be unique within a form. In fact, it appears that
with form submission, data would be sent like so:
<FORM action="..." method="get">
<INPUT name="address" value="My house number">
<INPUT name="address" value="My street">
<INPUT name="address" value="My city">
</FORM>
....?address=My +house+number&a ddress=My+stree t&address=My+ci ty
That is, all data, in the order it appears in the document.
I have a question though. I know very little of the DOM, so I was
wondering if someone could tell me how you would know what form
elements came from which form if you retrieved them using
HTMLDocument.ge tElementsByName (). After obtaining the collection
returned, would you use Node.parentNode to get a HTMLFormElement
object, then HTMLFormElement .name to get the name? So, for the first
matching name (we'll assume it will be in a form), would it be
something like this?
function getFormContaini ng( elementName ) {
var matches = document.getEle mentsByName( elementName );
return matches[ 0 ].parentNode.nam e;
}
Mike
I will learn about the DOM someday...
--
Michael Winter M.******@blueyo nder.co.uk.invalid (remove ".invalid" to reply)
Lasse Reichstein Nielsen wrote on 27 Nov 2003: Michael Winter <M.******@bluey onder.co.uk.inv alid> writes:
Two controls in different forms can use the same name, but what Dr Stockton wanted to do was use several text boxes with the same name in the same form, which you cannot do.
That is what I was asking for a reference for. I can't find that restriction in the HTML specification.
Please ignore that - read my other post.
Mike
--
Michael Winter M.******@blueyo nder.co.uk.invalid (remove ".invalid" to reply)
Michael Winter <M.******@bluey onder.co.uk.inv alid> writes: ...?address=My+ house+number&ad dress=My+street &address=My+cit y
That is, all data, in the order it appears in the document.
I wouldn't depend on the order. Other browsers could change that
without warning
I have a question though. I know very little of the DOM, so I was wondering if someone could tell me how you would know what form elements came from which form if you retrieved them using HTMLDocument.ge tElementsByName ().
All form controls have a property, "form", that is a reference to
the form they are within.
After obtaining the collection returned, would you use Node.parentNode to get a HTMLFormElement
No. The form doesn't need to be the immediate parent node of the
form control (and usually isn't).
return matches[ 0 ].parentNode.nam e;
return matches[0].form.name;
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Lasse Reichstein Nielsen wrote on 27 Nov 2003: Michael Winter <M.******@bluey onder.co.uk.inv alid> writes:
...?address=My+ house+number&ad dress=My+street &address=My+cit y
That is, all data, in the order it appears in the document.
I wouldn't depend on the order. Other browsers could change that without warning
You should be able to. That is defined in the specification:
For application/x-www-form-urlencoded (which includes anything
submitted with the GET method), "The control names/values are listed
in the order they appear in the document."
For multipart/form-data, "The parts are sent to the processing agent
in the same order the corresponding controls appear in the document
stream."
I don't know if scripting languages have that order imposed, though
(I haven't looked, nor do I quite know where to look).
<snipped reply to DOM question>
OK, thank you.
Mike
--
Michael Winter M.******@blueyo nder.co.uk.invalid (remove ".invalid" to reply) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Christopher |
last post by:
Hi
I need to know how to work with a control array in c#. I would
like to clear the contents of a textbox array after adding up the
values in the textboxes. This is really easy in VB6 - im sure it easy
in C# aswell - i just need the syntax.
Thanks in anticipation
Christopher
|
by: Peter Krikelis |
last post by:
Hi,
Finally figured events and delegates whew! Thanks to the people in this
community that helped me out.
So now I have a class that raises an event.
Now if I instantiate an object array of that class, and the event fires, is
there any way of getting the array index of the object that raised that event?
|
by: news |
last post by:
Can .NET handle the old system of arrays for controls used in Visual Basic?
eg
TextBox(1), (2) ...
|
by: Bernie |
last post by:
Sorry, but this ia another whine about VB.Net's lack of
Control Arrays. I am new to VB.Net and I'm building an
application that uses variable number of Label controls
that are created at run time. The number of label
controls will vary between 50 and 200. I have created an
array of labels and placed them on the form. It works
great, BUT I have not been able to raise any events for
these controls. I made a small demo with 9 labels...
|
by: John |
last post by:
Hello everyone,
I'm currently writing a program to keep track of schedule changes at a
school. The goal is to have someone using the program to declare changes,
then the program writes a html file, which is uploaded to a webserver. Then
students and teachers can view it online, but there are also a couple of
computers with 19" monitors standing around the school to display the
webpage (IE kiosk mode).
The program has a form containing...
| |
by: Greg |
last post by:
In VB6 I made heavy use of control arrays
I see they have been 'deprecated' in vb.Net, with a questionable explanation
that they are no longer necessary which just addresses the event issue!
Problem is I commonly associated several other controls with the same index
inside the event handler - eg a
Directory listbox, Label, Checkbox, Textbox Drivebox etc all associated with
identical index.
Now I see Control arrays belong to VB6...
|
by: Diarmuid |
last post by:
Are there control arrays in vb.net 2005?
Maybe some one could help me out with an example. I know how to this in VB6.
My database is called Planner.mdb
There is a table called Weekdays.
I want to read the first record in, and use that to set my labels as follows
me.lblDay1 = WeekDays!Day1
me.lblDay2 = WeekDays!Day2
and so on. In VB6 I would have done this in a for loop. Something like
me.lblDays(iLoop_ = rsWeekdays("Day" & iLoop)
|
by: Robert Boudra |
last post by:
I remember when VB.net came out that a couple of the seminars I went to
mentioned that Control Arrays were going away and that there was a new and
better way to execute the same code when an event occurs in one of a group
of similar controls. Unfortunately, that was several years ago, and I don't
remember how to do this. Can someone refresh my memory?
Bob
|
by: Brian Shafer |
last post by:
Hi,
I loved being about to use control arrays in vb classic. Doesn't look like
i can do this in vb.net?
Any input?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |