How can I prevent scroll-to-top when manipulating nodes?

R

Richard Trahan

I have a form larger than a screen. When some radio buttons or
checkboxes are clicked, I need to change the contents of a
select (menu) box by rebuilding the select node. That method
is necessary because I am using groups, which don't seem to have
a clean way to compose them (like selectnode.options =
new Option(mystring)).

A side effect of rebuilding the node is that the form scrolls
to the top, a really annoying effect I would like to avoid. Is
there any way to do this? I'm writing only for NN 7.2.
 
M

Michael Winter

[snip]
A side effect of rebuilding the node is that the form scrolls
to the top, a really annoying effect I would like to avoid. Is
there any way to do this? I'm writing only for NN 7.2.

Code? URL?

Mike
 
R

Richard Trahan

Michael Winter wrote:
(snip)

Thank you for responding.

Here's some code:

function construct_graph_selection_node()
{
var all = graphset.all; // speed access
var newselnode =
document.forms["formgraphs"]["selectgraphs"].cloneNode(false);
// This will replace the current select node
var nodeforoptions = newselnode; // where the next option (graph) will go
for(var i=0;i<all.length;++i) {
var typ = typeof(all);
switch(typ) {
case "object": // an option (of type Graph)
// options always become children of the current node
var newopt = document.createElement("option");
newopt.setAttribute("value",all.getName());
var txt = document.createTextNode(all.getName());
newopt.appendChild(txt); // won't display without this
nodeforoptions.appendChild(newopt); // add option to the
appropriate node
break;
case "string":
var newopt = document.createElement("optgroup");
newopt.setAttribute("label",all);
newselnode.appendChild(newopt); // groups are always added to the
selection node
odeforoptions = newopt; // but the next option goes here
break;
}
}
var fnode = document.formgraphs;
fnode.replaceChild(newselnode,fnode.selectgraphs);
}

The culprit is the replaceChild call, which causes a scroll to top.
 
M

Michael Winter

[snip]
var fnode = document.formgraphs;
fnode.replaceChild(newselnode,fnode.selectgraphs);
}

The culprit is the replaceChild call, which causes a scroll to top.

So if you commented-out that call, there's no scrolling?

I assume it's not something daft like you're calling the function from a
link but forgot to cancel the event.

My only thoughts at the moment is that replaceChild removes the targeted
node before adding the new one. This might cause the document to shrink in
size and scroll upwards.

Maybe someone else will have a better idea.

Good luck,
Mike
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top