help with select on element not working

0 views
Skip to first unread message

molo

unread,
Aug 7, 2009, 3:18:39 PM8/7/09
to Prototype & script.aculo.us
I have the following httml and javascript code (see snippets below).
I am running this using firebug

I am able to get the element lotTotalTr = $(accountTotal) to work
However the select on the element does not work. I have tried many
variations of the select
totalLotSharesTd = lotTotalTr.select('td.totalLotShares')

I was able to use lotTotalTr.childElements() and then
totalLotSharesTd3 = totalLotSharesTd2[3] to position myself where I
want to be but not select. This is not a good way to do this

Can anyone explain this to me?

--------------------------------------------------
<tr id="Total 87002B" class="TableRow1">
<td type="text">Total 87002B</td>
<td type="text"/>
<td type="text"/>
<td class="totalLotShares" name="totalLotShares" type="text">18031</
td>
<td type="text">316186.29</td>
<td type="text">316186.29</td>
<td type="text"/>
<td type="text"/>
</tr>

-----------------------------------------------------

function lotShareChange(obj){
var e = $(obj).up('tr');
var account = e.select('td input.account');
var accountVal = account[0].value;
var accountTotal = "Total " + accountVal;
var lotTotalTr = $(accountTotal);

var totalLotSharesTd;
var totalLotSharesTd2, totalLotSharesTd3, totalLotSharesTd4;

totalLotSharesTd = lotTotalTr.select('td.totalLotShares'); //
selects do not work
totalLotSharesTd2 = lotTotalTr.childElements(); //worked
totalLotSharesTd3 = totalLotSharesTd2[3]; //worked
totalLotSharesTd4 = lotTotalTr.select('td'); //does not work
//totalLotSharesTd = lotTotalTr.select('td');

totalLotSharesTd3.update(totalShares);


}

T.J. Crowder

unread,
Aug 8, 2009, 4:12:38 AM8/8/09
to Prototype & script.aculo.us
Hi,

> I am able to get the element lotTotalTr = $(accountTotal) to work

IDs cannot contain spaces[1]. Apparently you're getting away with it
on the $() call (the underlying getElementById must be allowing it),
spaces have meaning in selectors. Invalid IDs will not work reliably.

[1] http://www.w3.org/TR/html401/types.html#type-name

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

T.J. Crowder

unread,
Aug 8, 2009, 4:14:28 AM8/8/09
to Prototype & script.aculo.us
The word "but" is missing from the above "...allowing it), _but_
spaces have..."

molo

unread,
Aug 10, 2009, 10:53:19 AM8/10/09
to Prototype & script.aculo.us
Thanks so much T.J., that was the problem. I never would have gotten
that

Maurice

ColinFine

unread,
Aug 18, 2009, 11:03:04 AM8/18/09
to Prototype & script.aculo.us


On Aug 10, 3:53 pm, molo <maurice_lowent...@ssga.com> wrote:
> Thanks so much T.J., that was the problem. I never would have gotten
> that
>

Incidentally (and not on topic for your question)
<td/>
is not valid in either HTML or XHTML.

Also, <td> does not have a 'type' attribute. I believe browsers
generally do let you set an arbitrary attribute (though I haven't
found anything in the HTML spec that explicitly permits it), but it
seems an odd thing to do: did you mean to say 'class="text"'?

T.J. Crowder

unread,
Aug 18, 2009, 11:47:21 AM8/18/09
to Prototype & script.aculo.us
Colin,

> Incidentally (and not on topic for your question)
> <td/>
> is not valid in either HTML or XHTML.

It's valid XHTML for an empty table cell.

> Also, <td> does not have a 'type' attribute. I believe browsers
> generally do let you set an arbitrary attribute (though I haven't
> found anything in the HTML spec that explicitly permits it)...

It is in fact verboten. In HTML5, though, we're allowed to use our
own attributes as long as their names start with "data-", e.g.:

<td data-foo='bar'>

...is valid but

<td foo='bar'>

...is not.
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

ColinFine

unread,
Aug 19, 2009, 5:24:42 AM8/19/09
to Prototype & script.aculo.us


On Aug 18, 4:47 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> Colin,
>
> > Incidentally (and not on topic for your question)
> > <td/>
> > is not valid in either HTML or XHTML.
>
> It's valid XHTML for an empty table cell.
>

Wrong. It's a common misconception (which I had myself until
recently).

"All elements other than those declared in the DTD as EMPTY must have
an end tag. Elements that are declared in the DTD as EMPTY can have an
end tag or can use empty element shorthand (see Empty
Elements)." (http://www.w3.org/TR/2002/REC-xhtml1-20020801/#h-4.3)

That is, elements DECLARED TO BE EMPTY may use the shorthand. Elements
which happen to have no content may not.

I discovered this when Firefox correctly objected to <td/> or
something when I had given it an XTHML-Strict DOCTYPE.

> > Also, <td> does not have a 'type' attribute. I believe browsers
> > generally do let you set an arbitrary attribute (though I haven't
> > found anything in the HTML spec that explicitly permits it)...
>
> It is in fact verboten.  

Is it? I couldn't find an explicit statement that only the defined
attributes were permitted, though it is implied (and I thought I had
found somewhere in the HTML spec where it referred to 'attributes
defined in this specification', which might be taken to imply that
other attributes were permitted; but I can't find that now).

T.J. Crowder

unread,
Aug 20, 2009, 4:39:44 AM8/20/09
to Prototype & script.aculo.us
Hi Colin,

> > > Incidentally (and not on topic for your question)
> > > <td/>
> > > is not valid in either HTML or XHTML.
>
> > It's valid XHTML for an empty table cell.
>
> Wrong. It's a common misconception (which I had myself until
> recently).

If so, it's a misconception the W3C's own validator shares.
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

ColinFine

unread,
Aug 20, 2009, 10:06:06 AM8/20/09
to Prototype & script.aculo.us


On Aug 20, 9:39 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> Hi Colin,
>
> > > > Incidentally (and not on topic for your question)
> > > > <td/>
> > > > is not valid in either HTML or XHTML.
>
> > > It's valid XHTML for an empty table cell.
>
> > Wrong. It's a common misconception (which I had myself until
> > recently).
>
> If so, it's a misconception the W3C's own validator shares.

You're right. How bizarre. The spec clearly says no.

I'm sure I discovered this restriction because Firefox objected once,
but I can't think in what context.

ColinFine

unread,
Aug 20, 2009, 12:43:35 PM8/20/09
to Prototype & script.aculo.us


On Aug 20, 9:39 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> Hi Colin,
>
> > > > Incidentally (and not on topic for your question)
> > > > <td/>
> > > > is not valid in either HTML or XHTML.
>
> > > It's valid XHTML for an empty table cell.
>
> > Wrong. It's a common misconception (which I had myself until
> > recently).
>
> If so, it's a misconception the W3C's own validator shares.

Apologies - I was wrong. After discussion with somebody from W3C I now
understand that the section I was quoting is informative not
normative. I do think that it is misleading however (and I'm sure I
discovered this apparent limitation when something - I thought it was
firefox - threw out a construct like <div/>).

Both the XML and XHTML specs recommend not using the short form for
elements which are not defined as EMPTY, but they do not forbid it.

T.J. Crowder

unread,
Aug 20, 2009, 4:40:28 PM8/20/09
to Prototype & script.aculo.us
Thanks, Colin, glad it was something like that.

-- T.J. :-)
Reply all
Reply to author
Forward
0 new messages