Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Table containing Javascript to build cells
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jukka K. Korpela  
View profile  
 More options Jan 12 2011, 2:35 am
Newsgroups: alt.html
From: "Jukka K. Korpela" <jkorp...@cs.tut.fi>
Date: Wed, 12 Jan 2011 09:35:57 +0200
Local: Wed, Jan 12 2011 2:35 am
Subject: Re: Table containing Javascript to build cells

P E Schoen wrote:
> I have a table which is filled with name, title, email, and phone
> numbers. To make it easier to maintain I create a script which adds
> the rows and items from an array.

Such things are usually better done with server-side scripting than with
client-side JavaScript.

>                 </tr>
>         <script language="JavaScript" src="contacts.js"
> type="text/javascript"> </script>
>               </tbody>
>             </table>

You have placed the <script> element between the </tr> and </tbody> tags.
That's not allowed, since it would make the <script> a child of <tbody>, and
a <tbody> cannot have any other children but <tr> elements.

Usually you could either move the <script> element at the end of the last
<td> element or, better, after the <table> element. Depending on the
scripting logic, it might be best to move the <script> element even to the
<head> part of the document (usually the "cleanest" place for <script>
elements that contain variables and functions only) or at the very end of
the body, right before the </body> tag.

But, again, depending on scripting logic, you might need to do something
else.

> The script is:

>     var contact = new Array();

>     contact[0] = ["Name0", "Title0", "mailto:ema...@null.null",
> "000-555-5555"];

As an aside, the address is wrong, since the domain .null does not currently
exist. To indicate that an address-looking construct is just a dummy
example, use the .example or .example.com pseudo-domain. To use an
address-looking construct that detectable as invalid (e.g. for use as an
initial value that is expected to be overridden), use the .invalid
pseudo-domain.

>       document.write( "<tr><td ><p><b>" + contact[i][0] +

Here we go... using document.write() makes the <script> non-movable - this
is one of the many reasons for avoiding document.write().

With the current logic, there's not much to be done except accept
non-validity. It's after all a syntactic matter only, though it is
imagenable that some future browser might discard a <script> element that
appears in a place where the syntax does not allow it - though this is
highly unlikely.

A better logic would be to create the new elements using createElement() and
add them to the DOM tree with appendChild(). That way, the <script> element
could be placed at the end of the document. (It can't be in <head> because
it needs to access an existing element to find a place where it adds the
elements, and for this, you need to ensure that the document has loaded
before the script starts running.)

> I can probably construct the entire table with the script.

Certainly. And this would another way to fix the problem.

> I did not
> see any information about script not allowed within a table. I
> referred to http://www.w3.org/TR/html4/interact/scripts.html

It's not there, because the recommendation specifies what the allowed
content of an element is, and such rules only implicitly defined the allowed
contexts of an element (i.e. where an element may appear). The
www.htmlhelp.com site contains a nice HTML 4 reference where the context
rules have been explicitly written out, see e.g.
http://www.htmlhelp.com/reference/html40/special/script.html

--
Yucca, http://www.cs.tut.fi/~jkorpela/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.