Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Null object when populating drop downs

Status
Not open for further replies.

senglish

Programmer
Nov 4, 2002
19
AU
I am getting this message using some script that I got from the web
I actually found almost identical script from two sources and both give same problem
Error: 'document.globe.region' is null or not an object

The problem is in the onchange of this FORM script
<FORM name="globe">
<SELECT name="region" onchange="populateCountry(document.globe,document.globe.region.options[document.globe.region.selectedIndex].value)">
<OPTION value="">Select Region</OPTION>
<OPTION value="asia">Asia</OPTION>
<OPTION value="africa">Africa</OPTION>

</SELECT>
<SELECT name="country" onchange="populateUSstate(document.globe,document.globe.country.options[document.globe.country.selectedIndex].text)">
<OPTION value="">&lt;--------------------</OPTION>
</SELECT>
</FORM>


Script code is below
<script language="javascript" >

<!-- Begin-->
var africaArray = new Array("('Select country','',true,true)",
"('Ethiopia')",
"('Somalia')",
"('South Africa')",
"('Other')");
var asiaArray = new Array("('Select country','',true,true)",
"('Armenia')",
"('Bangladesh')",
"('Cambodia')",
"('China')",
"('India')",
"('Other')");

function populateCountry(inForm,selected)
{
var selectedArray = eval(selected + "Array");
while (selectedArray.length &lt; inForm.country.options.length)
{
inForm.country.options[(inForm.country.options.length - 1)] = null;
}
for (var i=0; i &lt; selectedArray.length; i++)
{
eval("inForm.country.options=" + "new Option" + selectedArray);
}
if (inForm.region.options[0].value == '')
{
inForm.region.options[0]= null;
if ( navigator.appName == 'Netscape')
{
if (parseInt(navigator.appVersion) &lt; 4)
{
window.history.go(0);
}
else
{
if (navigator.platform == 'Win32' || navigator.platform == 'Win16')
{
if(!document.getElementById)
window.history.go(0);
}
}
}
}
}
function populateUSstate(inForm,selected) {
var stateArray = new Array("('Select State','',true,true)",
"('Alabama')",
"('Wyoming')");
if (selected == 'USA') {
for (var i=0; i &lt; stateArray.length; i++) {
eval("inForm.country.options=" + "new Option" + stateArray);
}
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) &lt; 4) {
window.history.go(0)
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0)
}
}
}
}
else {
}
if (selected == 'Other') {
newCountry = "";
while (newCountry == ""){
newCountry=prompt ("Please enter the name of your country.", "");
}
if (newCountry != null) {
inForm.country.options[(inForm.country.options.length-1)]=new Option(newCountry,newCountry,true,true);
inForm.country.options[inForm.country.options.length]=new Option('Other, not listed','Other');
}
}
if(inForm.country.options[0].text == 'Select country') {
inForm.country.options[0]= null;
}
}// End -->

</script>
 
your problem is that you need to put the script in the head section of your page
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top