Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sorting

11 views
Skip to first unread message

fulio pen

unread,
May 18, 2013, 8:40:34 PM5/18/13
to
Hello,

Please open the following page. My intention is that when clicking
the head of a column, sorting will happen. But nothing has happened
so far.

http://www.pinyinology.com/css/officials2b.html

I wrote some js code, but it obviously didn't work. Please help
modify the code. Thanks a lot.

fulio pen

Andrew Poulos

unread,
May 18, 2013, 10:06:56 PM5/18/13
to
IE9 reports

Message: Syntax error
Line: 73
Char: 1
Code: 0
URI: http://www.pinyinology.com/css/officials2b.html

Andrew Poulos

Scott Sauyet

unread,
May 18, 2013, 10:10:40 PM5/18/13
to
Sorry, that's not the way it generally works around here. Please do
some more work first.

Post a well-formatted, brief version of your code here. Explain what
you think should happen with it and why. Describe what actually
happened. Tell us what sorts of things you've tried in order to fix
it.

Please read both of the following documents:

<http://jibbering.com/faq/#posting>
<http://www.catb.org/esr/faqs/smart-questions.html>

-- Scott

Denis McMahon

unread,
May 18, 2013, 10:15:43 PM5/18/13
to
On Sat, 18 May 2013 17:40:34 -0700, fulio pen wrote:

> Please open the following page. My intention is that when clicking the
> head of a column, sorting will happen. But nothing has happened so
> far.

Do you want something like this:

http://www.sined.co.uk/tmp/pinyin.htm

--
Denis McMahon, denismf...@gmail.com

Stefan Weiss

unread,
May 18, 2013, 10:44:55 PM5/18/13
to
On 2013-05-19 02:40, fulio pen wrote:
> Please open the following page. My intention is that when clicking
> the head of a column, sorting will happen. But nothing has happened
> so far.

I'm not surprised. Clicking one of the links just loads the same page
with a new query string ("?sortByID", "?sortBydob", ...), that's all.
The table won't magically sort itself just because the URL is different.

> http://www.pinyinology.com/css/officials2b.html
>
> I wrote some js code, but it obviously didn't work. Please help
> modify the code. Thanks a lot.

I'm not sure where to start... there aren't any functions that could
modify the table or the source array, and the rest is full of errors.

First of all, you should eliminate the HTML errors.
http://validator.w3.org/ can help with that.

One very obvious problem is this:

<head>
...
<script>
<!--
...
</script>
</head>
<body>
...
<script>
...
-->
</script>

Look at where the comments start and end. This may have caused the
syntax error in IE that Andrew posted (can't test due to lack of IE).
Using HTML comments to hide JS code from old browsers hasn't been
necessary for eons; just remove them.

Next, you should let your script read the query string and react
appropriately (by sorting the array before you write() the table).

If you're more interested in the result than how to get there, you could
also use a library to handle the table sorting for you. Many libraries
have something like that built-in or available as a plugin.
For example: http://vxweb.net/sortable#example


- stefan

Thomas 'PointedEars' Lahn

unread,
May 19, 2013, 5:23:59 AM5/19/13
to
fulio pen wrote:

> Please open the following page.

No.

--
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

fulio pen

unread,
May 19, 2013, 6:43:52 PM5/19/13
to
On May 18, 10:44 pm, Stefan Weiss <krewech...@gmail.com> wrote:
> On 2013-05-19 02:40, fulio pen wrote:
>
> > Please open the following page.  My intention is that when clicking
> > the head of a column, sorting will  happen.   But nothing has happened
> > so far.
>
> I'm not surprised. Clicking one of the links just loads the same page
> with a new query string ("?sortByID", "?sortBydob", ...), that's all.
> The table won't magically sort itself just because the URL is different.
>
> >http://www.pinyinology.com/css/officials2b.html
>
> > I wrote some js code, but it obviously didn't work.  Please help
> > modify the code.  Thanks a lot.
>
> I'm not sure where to start... there aren't any functions that could
> modify the table or the source array, and the rest is full of errors.
>
> First of all, you should eliminate the HTML errors.http://validator.w3.org/can help with that.
Thanks to all for your help. A while ago someone helped me with a
sorting in the following page:

http://www.pinyinology.com/sortable/shuihu/heavenly.html?sortByName

The code worked. This time I just wanted to following suit in another
sorting by myself:

http://www.pinyinology.com/css/officials2b.html

But the code didn't work. Thank you again.

fulio pen

fulio pen

unread,
May 19, 2013, 7:37:42 PM5/19/13
to
On May 18, 10:44 pm, Stefan Weiss <krewech...@gmail.com> wrote:
> On 2013-05-19 02:40, fulio pen wrote:
>
> > Please open the following page.  My intention is that when clicking
> > the head of a column, sorting will  happen.   But nothing has happened
> > so far.
>
> I'm not surprised. Clicking one of the links just loads the same page
> with a new query string ("?sortByID", "?sortBydob", ...), that's all.
> The table won't magically sort itself just because the URL is different.
>
> >http://www.pinyinology.com/css/officials2b.html
>
> > I wrote some js code, but it obviously didn't work.  Please help
> > modify the code.  Thanks a lot.
>
> I'm not sure where to start... there aren't any functions that could
> modify the table or the source array, and the rest is full of errors.
>
> First of all, you should eliminate the HTML errors.http://validator.w3.org/can help with that.
Hi, Stefan,

With the html validator, I had one mistake, and understood that the
comment line <!-- had to be added, which I did. but the mistake
wouldn't be eliminated. If possible, please tell me what to do.
Following is the comments on that mistake.


Line 88, Column 31: Element script not allowed as child of element
tbody in this context. (Suppressing further errors from this subtree.)
<script type='text/javascript'>
Contexts in which element script may be used:
Where metadata content is expected.
Where phrasing content is expected.
Content model for element tbody:
Zero or more tr elements

Thanks for your help.

fulio pen

Denis McMahon

unread,
May 19, 2013, 8:37:27 PM5/19/13
to
On Sun, 19 May 2013 16:37:42 -0700, fulio pen wrote:

> Line 88, Column 31: Element script not allowed as child of element tbody
> in this context. (Suppressing further errors from this subtree.)

What it means is that you can't use <script></script> at that point in a
table.

However, you don't need to put script in that point in the table at all.

If you want a script to run when the document body is loaded, it may be
better to put it in the document head script section as a function, and
then use the onload attribute of the body to call it.

In addition, your calls to the javascript functions from links will not
work that way. If you want to call a javascript function from a link, you
need to specify the javascript protocol and the function, eg:

<a href="javascript:function();" ....>link text</a>

However, it is often just as easy to call Javascript functions using the
onclick handler of a span or some other element.

<span onclick="function();" ....>text</span>

Finally, sorting the data will not change the table, you need to
(re)populate the table with the sorted data afterwards.

I've just edited my example, if you looked at it earlier you may want to
look again - I realised I was doing extra work manipulating the table
that wasn't needed.

--
Denis McMahon, denismf...@gmail.com

fulio pen

unread,
May 20, 2013, 10:13:30 AM5/20/13
to
> Denis McMahon, denismfmcma...@gmail.com

Dennis,

Thanks a lot for your help.

fulio pen
0 new messages