"name" attribute.......more than one use?

R

Richard

<a href="#" name="sample">link 1</a>
<a href="#" name="sample">link 2</a>

Would this be invalid use of the name?
If I wanted to have a function that would be acted upon by detection of the
"name", would this happen if all "name"s in a group were the same?
I know ID can only be used once per document, what about "name"?

If this is invalid, then if I went by a unique ID, such as sample1, sample2,
sampl3, is there a way to eliminate the number on the end to check if the
strings match what I'm looking for?

For those of you familiar with ancient BASIC, we could easily do this by
saying something like A$=left$(b$,6).
Where A$ would return the first 6 characters of b$.
So does JS have an equivelant?
 
L

Lee

Richard said:
<a href="#" name="sample">link 1</a>
<a href="#" name="sample">link 2</a>

Would this be invalid use of the name?
If I wanted to have a function that would be acted upon by detection of the
"name", would this happen if all "name"s in a group were the same?
I know ID can only be used once per document, what about "name"?

The name attribute does not have to be unique.
Your use is valid.

If this is invalid, then if I went by a unique ID, such as sample1, sample2,
sampl3, is there a way to eliminate the number on the end to check if the
strings match what I'm looking for?

For those of you familiar with ancient BASIC, we could easily do this by
saying something like A$=left$(b$,6).
Where A$ would return the first 6 characters of b$.
So does JS have an equivelant?

A=b.substr(0,6)
 
R

RobG

Richard said:
<a href="#" name="sample">link 1</a>
<a href="#" name="sample">link 2</a>

Would this be invalid use of the name?

Yes - read the spec. In regard to <a> tags:

"This attribute names the current anchor so that it may be the
destination of another link. The value of this attribute must be a
unique anchor name. The scope of this name is the current document.
Note that this attribute shares the same name space as the id
attribute."

<URL:http://www.w3.org/TR/html4/struct/links.html#adef-name-A>

All tag attributes and the tags that they apply to, along with links
to explainations of each are here:

<URL:http://www.w3.org/TR/html4/index/attributes.html>

Whenever you are tempted to ask a question such as that above, read the
spec first.

If I wanted to have a function that would be acted upon by detection of the
"name", would this happen if all "name"s in a group were the same?
I know ID can only be used once per document, what about "name"?

Sometimes name must be unique, sometimes is should not be used and
sometimes it is mandatory. Check the specification each time you want
to use it.
 
F

Fred Oz

Lee said:
Richard said:
<a href="#" name="sample">link 1</a>
<a href="#" name="sample">link 2</a>
[...]

The name attribute does not have to be unique.
Your use is valid.

Wrong. In regard to named links, the name attribute *must* be unique
and it shares the same namespace as ID, so it must not match an ID
either.
 
R

Richard

Yes - read the spec. In regard to <a> tags:
"This attribute names the current anchor so that it may be the
destination of another link. The value of this attribute must be a
unique anchor name. The scope of this name is the current
document.
Note that this attribute shares the same name space as the id
attribute."

All tag attributes and the tags that they apply to, along with links
to explainations of each are here:

Whenever you are tempted to ask a question such as that above, read
the
spec first.


I would if I knew how w3 was structured to find these things out.
Like they make it so easy.
I thought it had to be unique but I wasn't sure if that was correct or not.
 
R

RobG

Richard wrote:
[...]
I would if I knew how w3 was structured to find these things out.
Like they make it so easy.
I thought it had to be unique but I wasn't sure if that was correct or not.

Here is the start of the W3C HTML 4.01 spec. It is the table of
contents and has links to everything to do with HTML.

<URL:http://www.w3.org/TR/html4/>

At the bottom are links to references, notably a list of all the
elements and all the attributes.

The only way to get to know it is to start using it - think of an
element, say <p> and look it up, it's in chapter 9, titled:

"Text - Paragraphs, Lines, and Phrases"

Click the link, it takes you here:

<URL:http://www.w3.org/TR/html4/struct/text.html>

Or, to go via the Index of elements, go to the bottom of the table of
contents (where references are normally listed), and click on the link
to here:

<URL:http://www.w3.org/TR/html4/index/elements.html>

scroll down to "P", click on it and you go here:

<URL:http://www.w3.org/TR/html4/struct/text.html#edef-P>

Now you know how I use it, try it.
 

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,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top