473,847 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I create an array of tags by assigning same name?

Hi,

Can I create an array of tags by assigning same name to these tags?
For example, I have two <p> tags with the same name t1. But

document.all.b. value=document. all.t.length

does not work. It works if the tags are <input type=radio...>. This
line is OK:

document.all.bt n.value=documen t.all.b.length
What are the tags that can be use as an array of tags by assigning
same name to these tags?
<HTML><script language="JavaS cript">
function checkButtonSets (){
//document.all.bt n.value=documen t.all.t.length
document.all.bt n.value=documen t.all.b.length
}</script><HEAD>

<BODY>
<p name="t" id=q></p>
<p name="t" id=q></p>
<input type="Radio" name="b" value="a2">a2
<input type="Radio" name="b" value="a3">a3<b r>
<input name="btn" type="Button" value="Check Button Sets"
onClick="checkB uttonSets()">
</BODY></HTML>
Jul 23 '05 #1
1 2182
je************@ hotmail.com (Jenny) writes:
Can I create an array of tags by assigning same name to these tags?
If I understand your question correctly, then no, not in standard
compliant browsers.
For example, I have two <p> tags with the same name t1.
<p> tags does not have a "name" attribute in HTML, and if you
want to use the "id" attribute, they can't have the same value
either, since id's must be unique.

Make sure you write correct, validating HTML, or you won't
be able to predict how Javascript will work on it, especially
across browsers.
But

document.all.b. value=document. all.t.length
"document.a ll" is a proprietary Microsoft invention. It will not
work in many other browsers.

I guess that "b" is the name of a form element, and "t" is the "name"
of the two <p> elements (in HTML, the (opening and closing) tags
delimiter the HTML *element*, which is what we are interested in).

There is no stadard compliant way to get a set of elements by their
attributes (except document.getEle mentsByName, which doesn't apply
to paragraph elements, since they don't have name attributes).

If they are the only paragraph elements, you can get them as:
var paragraphs = document.getEle mentsByTagName( "p");
Otherwise, you will probably have to iterate through the paragraphs,
or all elements (document.getEl ementsByTagName ("*")) to find the ones
you want.
does not work. It works if the tags are <input type=radio...>. This
Input elements have "name" attributes.
line is OK:

document.all.bt n.value=documen t.all.b.length
I would recommend:
---
document.forms['formName'].elements['btn'].value =
document.forms['formName'].elements['b'].length;
---
if the input elements are in the form with id="formName", or:
---
document.getEle mentById("btn") .value =
document.getEle mentsByName("b" ).length;
---
if they are not inside a form (and the "btn" element has "btn" as
an "id" instead of a "name", which is appropriate for a unique
identifier).
What are the tags that can be use as an array of tags by assigning
same name to these tags?
Form controls (input, button, textarea, select, and object). They
have name attributes, and there are allowed to be more than one
with the same name.
<HTML><script language="JavaS cript">
The "language" attribute is deprecated, and the "type" attribute is required,
in HTML 4, so the script tag should be:
<script type="text/javascript">

Script elements must be inside either the <head> or <body> elements.
This one is placed before "<HEAD>", which is incorrect (yeah, browsers
accept it, but again, incorrect HTML makes scripts unpredictable)
function checkButtonSets (){
//document.all.bt n.value=documen t.all.t.length
document.all.bt n.value=documen t.all.b.length
document.getEle mentById("btn") .value = // see below for id="btn"
document.getEle mentsByName("b" ).length;
}</script><HEAD>

<BODY>
<p name="t" id=q></p>
<p name="t" id=q></p>
The "id" attributes must have unique values, so you can't call both of
them "q".
<input type="Radio" name="b" value="a2">a2
<input type="Radio" name="b" value="a3">a3<b r>
<input name="btn" type="Button" value="Check Button Sets"
I'd give this input element an id="btn" instead of the "name" attribute,
and then use the line above.
onClick="checkB uttonSets()">
</BODY></HTML>


Good luck!
/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.'
Jul 23 '05 #2

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

Similar topics

3
11484
by: John MacIntyre | last post by:
Hi, Can anybody give me a hint as to how to convert a javascript array into a vbscript array? BTW-it only needs to work in IE5 & 6 Thanks in advance, John MacIntyre VC++ / VB / ASP / Database Developer
58
10206
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
38
5262
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please let's us do not go into an "each dot over i" clarification discussion now - however you want to call - you call it ;-) array contains records of all files in the current dir. array contains records of all subs in the current dir
7
1650
by: Jake Thompson | last post by:
Hello I have the following defined structure struct cm8linkstruc { char *type; /* type of item*/ char *desc; /* description of item */ char *item_increment; /* increment value for item in folder */
45
4875
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to "new Array() vs " question or to the array performance, I dared to move it to a new thread. Gecko takes undefined value strictly as per Book 4, Chapter 3, Song 9 of Books of ECMA :-)
2
2519
by: JJA | last post by:
I'm looking at some code I do not understand: var icons = new Array(); icons = new GIcon(); icons.image = "somefilename.png"; I read this as an array of icons is being built. An element of the array is an object itself but what is this syntax of the consecutive double quotes inside the brackets ?
20
2049
Samji
by: Samji | last post by:
Hi, everyone. I have this code when I'm reading in a file: // read lines into array var line = {}, lines = , hasmore; do { hasmore = istream.readLine(line); lines.push(line.value); }
4
3833
Ispep
by: Ispep | last post by:
Hi, unfortunately having a bit of difficulty with a question from an Open University course I'm currently doing. If you could help me out in any way I'd be grafeul (though obviously it goes without saying I'm not asking you to solve the question - that won't help come exam time :(). Anyway I have a CSV delimited file in the following format; STRING,INT STRING,INT,INT,INT,INT,INT STRING,INT,INT,INT,INT,INT STRING,INT,INT,INT,INT,INT ...
0
9887
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9730
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,...
0
10983
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, 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...
1
7883
isladogs
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...
0
7056
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();...
0
5719
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4529
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
3
3164
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.