Please, anyone, tell me how can this be:

var cust_state = document.forms.info.dropdown_a.value;

// Displays "TX" or whatever state was selected. I tried removing this line; it doesn't help.
        alert("State: " + cust_state);

	if (cust_state == "XX") {
		eval('document.forms.info.dropdown_a.style.backgroundColor = "#FFCCCC";');
		eval('document.forms.info.dropdown_a.focus();');			
		alert("Please select a State from the drop-down box.");
		return false;
	}
	else {
		eval('document.forms.info.dropdown_a.style.backgroundColor = "#FFFFFF";');	
	}

Here is code that DOES work:

var cust_state = document.forms.info.cust_state.value;

	if (cust_state == "XX") {
		eval('document.forms.info.cust_state.style.backgroundColor = "#FFCCCC";');
		eval('document.forms.info.cust_state.focus();');
		alert("Please select a State from the drop-down box.");
		return false;
	}
	else {
		eval('document.forms.info.cust_state.style.backgroundColor = "#FFFFFF";');
	}

When I run this in IE 7.0 (which has the wonderful feature of displaying all JavaScript errors in a pop-up message), it gives me the error
"Object expected" at:

if (cust_state == "XX") {

Which makes NO SENSE because I just used that variable, and it displayed the value I entered! Moreover, there is no reason why it shouldn't work, since I'm getting the value properly, etc.

I've quadruple checked everything, about 20 times! I can't find out what's wrong here. I tried changing the name from field[6] to dropdown_1, then to dropdown_a just to eliminate some possibilities. BTW, field[1] through field[12] works fine with textboxes -- but though I could grab the value using field[13], I started having problems with this missing object error.

I even compared it to code that DOES STILL WORK and everything is the same! It's like the same code is working differently in 2 different files. Totally insane.

If anyone could help, I'd be most grateful.

Matthew

This article has been dead for over six months. Start a new discussion instead.