selectedIndex doesn't change?

Hi I have the following code, it is supposed to add an option to op4 if the selectedIndex of op2 is 0 and the value of op1 is “blah blah”

Point is, it adds a new option every time, and it’s because the selectedIndex of op2 doesn’t change.

function setJign()
var op1 = document.poles.op1;
var op2 = document.poles.op2; 
var op3 = document.poles.op3;
var op4 = document.poles.op4;

var $t = op1.options[op1.selectedIndex];
var $v = op2.selectedIndex;
	if($v = "0")
		if($t = "Jig N Pole - $24.00")
			op4.options[op4.options.length] = new Option('Cork Handle - $1');
	} else {
		op4.options.length = 0;
		op4.options[op4.options.length] = new Option('EVA Foam - $0');

The problem is that the selected index, as reported by the function, doesn’t change.

Firebug says that the selectedIndex changes, but the function doesn’t

Here is a link to the site

Please be gentle on the code, I’m new.

Thanks in advance for the help!

You are using assignments (=) instead of equality comparisons (==). That’s most likely your problem.

Change to,

if($v == "0")


if($t == "Jig N Pole - $24.00")

Thanks, can’t believe I didn’t see it.

Also just out of curiosity now, how can you get the value of a selected option?

Normally as sel.options[sel.selectedIndex].value or simply as sel.value (where sel is a reference to the <select> element).

Does that update after the page loads?

Such as if I got the value after it had been changed, would it reflect the change or just give me what was originally the value?

It gives you the value of the option that is selected when you execute the statement. If you assign the value to a variable, that variable will not change to reflect changes made on the page. But the statement itself (e.g., sel.value) always returns the currently selected value.

Thanks again for the help!