How can added attributes survive a page reload?

L

lcplben

Hi folks --

Consider a table column whose attributes the user can change. Beyond
changing the usual -- font-size, say -- he can indicate the sort order
of the values in the column. This needs (I think) an added attribute,
call it "sortOrder." So for column c the code might say:

c.setAttribute( "sortOrder", "descending" );

Now the user decides to reload the page and the table with its newly-
characterized column. What happens to sortOrder? It must evaporate,
right?

Well, I might preserve sortOrder by shipping that attribute to the
server when the user enters it. At reload time, that value is known by
my CGI. No problem. The CGI gets busy constructing the page to answer
the reload request, including filling in the sortOrder attribute. So
far so good.

But when the page gets to the browser, I think that sortOrder, a
mystery attribute to the browser, will /again/ disappear, so the
user's earlier work is lost, correct?

I could put sortOrder in the column's title attribute and send that to
the CGI. What a pain, though, to parse that thing coming in to the
client at onload time.

Now, finally, the question: short of using cookies, can you think of a
way to retain an added attribute over a page reload?

Thanks!

-- ben
 
T

Thomas 'PointedEars' Lahn

lcplben said:
Consider a table column whose attributes the user can change. Beyond
changing the usual -- font-size, say -- he can indicate the sort order
of the values in the column. This needs (I think) an added attribute,
call it "sortOrder."

It doesn't.
So for column c the code might say:

c.setAttribute( "sortOrder", "descending" );

The generated markup would most likely be not Valid.
Now the user decides to reload the page and the table with its newly-
characterized column. What happens to sortOrder? It must evaporate,
right?

If it was a liquid, then maybe yes. In all other cases, there are two
possibilities:

a) The attribute was not added in the first place;
b) the attribute, along with the rest of the document
ceases to exist in memory.
Now, finally, the question: short of using cookies, can you think of a
way to retain an added attribute over a page reload?

That depends on how you define "page" and "reload".


PointedEars
 
L

lcplben

Thank you, Thomas. I appreciate your giving your absolute best effort
in your answer.

-- ben
 
V

VK

But when the page gets to the browser, I think that sortOrder, a
mystery attribute to the browser, will /again/ disappear, so the
user's earlier work is lost, correct?

Not really, the relevant attribute node is created. The problem starts
when you are trying to get from your script, because different
browsers took different decisions about custom attributes. Some of
them provide the regular scriptable DOM interfaces just like for
default attributes:
elmTH.className = 'whatever';
elmTH.myCustomAtt = 'whatever';
The others provide scriptable interfaces only for default attributes
and "don't see" custom ones so you need to use getAttribute for it:
elmTH.className = 'whatever';
but
elmTH.setAttribute('myCustomAtt', 'whatever');
elmHT.getAttribute('myCustomAtt');
To overcome that use getAttribute for custom attributes and be
happy :)
 

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,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top