Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > spaces in names and id's

Reply
Thread Tools

spaces in names and id's

 
 
Jeff Thies
Guest
Posts: n/a
 
      06-10-2004
I have image names with spaces in them. Is that likely to cause any trouble?

<img src="x.gif" name="about us" id="foo bar">

I'm writing a little rollover code (first time for everything) and from my
bit of testing, spaces in image names seems to be fine. I'm pretty sure that
spaces in ID's is no good, at least it would be for setting styles. I know
that spaces in form names is OK. Is that about right?

Cheers,
Jeff


 
Reply With Quote
 
 
 
 
rf
Guest
Posts: n/a
 
      06-10-2004

"Jeff Thies" <(E-Mail Removed)> wrote in message
news:tyPxc.4468$(E-Mail Removed) k.net...
> I have image names with spaces in them. Is that likely to cause any

trouble?
>
> <img src="x.gif" name="about us" id="foo bar">
>
> I'm writing a little rollover code (first time for everything) and from my
> bit of testing, spaces in image names seems to be fine. I'm pretty sure

that
> spaces in ID's is no good, at least it would be for setting styles. I know
> that spaces in form names is OK. Is that about right?


The specifications:

http://www.w3.org/TR/html4/types.html#type-cdata

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed
by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"),
colons (":"), and periods (".").

I don't see space mentioned anywhere there.

Cheers
Richard.


 
Reply With Quote
 
 
 
 
Jeff Thies
Guest
Posts: n/a
 
      06-10-2004

"rf" <(E-Mail Removed)> wrote in message
news:eKPxc.64$(E-Mail Removed)...
>
> "Jeff Thies" <(E-Mail Removed)> wrote in message
> news:tyPxc.4468$(E-Mail Removed) k.net...
> > I have image names with spaces in them. Is that likely to cause any

> trouble?
> >
> > <img src="x.gif" name="about us" id="foo bar">
> >
> > I'm writing a little rollover code (first time for everything) and from

my
> > bit of testing, spaces in image names seems to be fine. I'm pretty sure

> that
> > spaces in ID's is no good, at least it would be for setting styles. I

know
> > that spaces in form names is OK. Is that about right?

>
> The specifications:
>
> http://www.w3.org/TR/html4/types.html#type-cdata
>
> ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed
> by any number of letters, digits ([0-9]), hyphens ("-"), underscores

("_"),
> colons (":"), and periods (".").
>
> I don't see space mentioned anywhere there.


So it is.

I can't tell you how many forms that I've seen with spaces in the form
names. I've always replaced them with underscores when I caught them. But
that was just my personal preference rather than a desire to do right!


Thanks,
Jeff
>
> Cheers
> Richard.
>
>



 
Reply With Quote
 
Stan McCann
Guest
Posts: n/a
 
      06-10-2004
Jeff Thies wrote:
> I'm writing a little rollover code (first time for everything) and from my
> bit of testing, spaces in image names seems to be fine. I'm pretty sure that
> spaces in ID's is no good, at least it would be for setting styles. I know
> that spaces in form names is OK. Is that about right?


Best not to use spaces for any of those things. While spaces may work
in one instance, they may not work in another.

--
Stan McCann
Webmaster/Computer Center Manager, NMSU at Alamogordo
Cooordinator, Tularosa Basin Chapter, ABATE of NM AMA#758681
'94 1500 Vulcan (now wrecked) http://surecann.com/Dcp_2068c.jpg
A zest for living must include a willingness to die. - R.A. Heinlein

 
Reply With Quote
 
Richard Cornford
Guest
Posts: n/a
 
      06-10-2004
rf wrote:
> Jeff Thies wrote:

<snip>
>> I'm writing a little rollover code (first time for everything) and
>> from my bit of testing, spaces in image names seems to be fine. I'm
>> pretty sure that spaces in ID's is no good, at least it would be for
>> setting styles. I know that spaces in form names is OK. Is that
>> about right?

>
> The specifications:
>
> http://www.w3.org/TR/html4/types.html#type-cdata
>
> ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
> followed by any number of letters, digits ([0-9]), hyphens ("-"),
> underscores ("_"), colons (":"), and periods (".").
>
> I don't see space mentioned anywhere there.


ID tokens apply to ID attributes, NAME tokens apply to NAME attributes
on META elements only. NAME attributes on IMG are specified as CDATA and
may contain spaces (there is some mention in the CDATA section of the
spec about UAs optionally trimming leading and trailing spaces from
CDATA so they may not be a good idea in a NAME attribute).

Space characters (and many others) would require additional care if the
corresponding elements were to be scripted, but that just involves using
the correct accessor syntax.

Richard.


 
Reply With Quote
 
Jukka K. Korpela
Guest
Posts: n/a
 
      06-10-2004
"Jeff Thies" <(E-Mail Removed)> wrote:

> I can't tell you how many forms that I've seen with spaces in the form
> names.


But that's a different issue. You asked about name and id attributes in
img elements.

The name attribute is actually very polymorphic - i.e., it has different
rules in different elements, or the name attributes in different elements
are really _different attributes_ which just incidentally share the same
name.

In _form fields_, the name attribute may (and often needs to) contain
just about anything. Spaces are no problem.

In <img> and <form> elements, the name attribute is not needed except for
certain modes of JavaScript coding and is not even allowed in all
versions of HTML. What you can put there if you use it depends on
JavaScript more than anything else.

The id attribute must by definition have a unique value of type ID, which
sets very strict syntax rules.

The name attribute in <a> may contain any string from the HTML
perspective, but since it is used for the purpose of using it in a
fragment identifier, it's best to stick to simple syntax, e.g. no spaces.
In theory, if you use <a name="foo bar">, you can then use
href="#foo%20bar" (i.e., with the space as URL encoded), but this is
clumsy, odd-looking, and not supported by all browsers.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html


 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      06-10-2004
"Jeff Thies" <(E-Mail Removed)> wrote in message news:<tyPxc.4468$(E-Mail Removed) nk.net>...

> I have image names with spaces in them. Is that likely to cause any trouble?
>
> <img src="x.gif" name="about us" id="foo bar">


What's a "name" ?

This examples looks as if you mean a human-readable "title" for the
image, so you'd be better putting that into the title attribute. This
can use whatever characters you like, subject to basic HTML encoding
rules (i.e. quote characters, angle brackets and ampersands are an
issue, but not spaces)

The name and id attributes are not intended for humans, they're
machine identifiers. These have tighter naming rules (read the specs)
and you certainly can't embed spaces.

Filenames and URLs should avoid spaces. They're permitted, but you
need to use the appropriate encoding to represent them. Browsers are
generally roubust here, so you can do things that are definitely wrong
and they'll still work, but it's bad practice and they might not
always work in all circumstances.
 
Reply With Quote
 
Magnus Haugsand
Guest
Posts: n/a
 
      06-10-2004
Jeff Thies wrote:
> I have image names with spaces in them. Is that likely to cause any trouble?
>
> <img src="x.gif" name="about us" id="foo bar">
>
> I'm writing a little rollover code (first time for everything) and from my
> bit of testing, spaces in image names seems to be fine. I'm pretty sure that
> spaces in ID's is no good, at least it would be for setting styles. I know
> that spaces in form names is OK. Is that about right?
>
> Cheers,
> Jeff
>
>


I do not now if the same applies to id, but class="foo bar" decides that
the element is both .foo and .bar

--
Mvh Magnus Haugsand
 
Reply With Quote
 
Jeff Thies
Guest
Posts: n/a
 
      06-10-2004
<snip>

>
> I do not now if the same applies to id, but class="foo bar" decides that
> the element is both .foo and .bar


Really? What is the level of support for it? That could be usefull.

Jeff
>
> --
> Mvh Magnus Haugsand



 
Reply With Quote
 
Magnus Haugsand
Guest
Posts: n/a
 
      06-10-2004
Jeff Thies wrote:
> <snip>
>
>>I do not now if the same applies to id, but class="foo bar" decides that
>>the element is both .foo and .bar

>
>
> Really? What is the level of support for it? That could be usefull.
>
> Jeff


I think even IE 5 supports it, but I am not sure if NS4 nor IE4 does.

--
Mvh Magnus Haugsand
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSD to allow A-Z 0-9 and spaces, but not leading/trailing spaces johkar XML 2 12-10-2009 09:24 AM
[CSS] how can I show spaces as spaces? Tomasz Chmielewski HTML 21 09-10-2009 06:43 PM
how can I show spaces as spaces, part 2 Tomasz Chmielewski HTML 14 09-10-2009 03:54 PM
Re: How to trim a String trailing spaces, but not leading spaces? Roedy Green Java 3 09-14-2008 02:10 AM
Re: How to trim a String trailing spaces, but not leading spaces? John B. Matthews Java 4 09-12-2008 05:28 AM



Advertisments