david <pa*********@server.com> writes:
i'm generating a select menu, with php/mysql. The menu contains
country names.
My problem is that i have ~ 250 countries in one of these menu and i
need from 6 to ten times this menu in a web page.
Whoa. with 250 options in a select element, you might want to consider
other ways of choosing (not sure which would be better, though, 250
options is a lot).
Is there any way for sharing the data between each menu? It should speed up
transfert and decrease size of the web page.
Yes, but then your page will not work if Javascript is disabled.
---
<script type="text/javascript">
function copyOptions(idFrom,idTo) {
var from = document.getElementById(idFrom);
var to = document.getElementById(idTo);
// maybe add sanity check: does both exist and are select elements
to.length = 0;
for (var i=0;i<from.length;i++) {
var opt = from.options[i];
to.options[i]=new Option(opt.text,opt.value);
}
}
function init() {
copyOptions("countrySel1","countrySel2");
copyOptions("countrySel1","countrySel3");
copyOptions("countrySel1","countrySel4");
copyOptions("countrySel1","countrySel5");
copyOptions("countrySel1","countrySel6");
}
</script>
---
and
---
<body onload="init()">
... <select id="countrySel1"><option>x250...</select>
... <select id="countrySel2"></select>
... <select id="countrySel3"></select>
---
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'