Marc wrote:
I've gotten everything up and running except for this -- I'd like to
be able to have people have a dropdown list of cities in the US to use
(or wherever) and not have to input them manually into a text field.
When you do then there are issues of misspellings, etc.
Now I have a list of cities from each state that is a sample that
works in an html page. Problem is that it takes up 2 MB! Way too much
to load on a single page and I was wondering how this is accomplished
best -- do people use javascripts that can pull information from
another flat flie? Do people use PHP to connect to a mysql database
that might have a list of these fields and then reloads the page?
I'm really not sure of best options and would be grateful for anyone
to give me pointers or whether there are other examples and even
places to buy these databases (not likely but good to have if I decide
to do so.)
/*does all processing on genenric amounts of linked selects!!!
<script type="text/javascript">
<!--
selects=new Array();
selects[0]=document.forms['FrmAdminControl'].elements['test.0'];
selects[1]=document.forms['FrmAdminControl'].elements['test.1'];
selects[2]=document.forms['FrmAdminControl'].elements['test.2'];
initLinkedSelect(selects);
-->
requires following names on options so we know what goes where
<select name"=test.0">
<option value="dog">Dog</option>
<option value="cat">Cat</option>
</select>
<select name="test.1">
<option value="dog-fido">Fido</option>
<option value="dog-rover">Rover</option>
<option value="cat-boots">Boots</option>
<option value="cat-pussy">Pussy</option>
</select>
<select> name="test.2">
<option value="dog-fido-dead">Dead</options>
....
....
</select>
*/
function initLinkedSelect(selects) {
var options = new Array();
var nextselect = new Array();
for (k = selects.length-2 ; k >= 0 ; k-- ){
from=selects[k];
to=selects[k+1];
options[from.name]=new Array();
(from.style || from).visibility = "visible";
for (var i=0; i < to.options.length; i++) {
options[from.name][i] = new
Array(to.options[i].text,to.options[i].value);
}
nextselect[from.name]=k;
from.onchange = function() {
to=selects[nextselect[this.name]+1];
var fromCode = this.options[this.selectedIndex].value+'-';
var selectedoption=0;
selectedoption=to.options[to.selectedIndex].text;
to.options.length = 0;
for (i = 0; i < options[this.name].length; i++) {
if (options[this.name][i][1].indexOf(fromCode) == 0) {
to.options[to.options.length] = new Option(options[this.name][i
[0],options[this.name][i][1]);
if(options[this.name][i][0]==selectedoption)
to.options[to.options.length-1].selected=true;
}
}
// to.options[selectedoption].selected = true;
if(selects[nextselect[to.name]] && selects[nextselect[to.name]].onchange
{
selects[nextselect[to.name]].onchange();
} else {
}
}
from.onchange();
}
}
--
Fletch
A: Because it disrupts the natural flow when reading
Q: Why is it bad to top post?