Calling a function onchange with a parameter

hmmmm, basically what i am trying to do is make an array of all the drop down menus (select tags) on the page, and store the values 0 - 9 to a cookie when it is changed.

the entire code i have written is below. it all works (almost!) and you can add this to any page and it will set up as long as the select s have an id (<select id=“xxx”>).

there is however, one problem. at the moment it only records the last select properly. this is because i have set the selectID var as a global. this means when it gos threw the for loop it keeps the value of the last select.

i set up selectID as a global as i couldnt work out how to call the function updateCookie by parsing a parameter to it.

selectValue.onchange = updateCookie;

if i…
selectValue.onchange = updateCookie(selectID);
…and update the updateCookie function to except this, it doesnt like it.

im pretty sure if i could work out another way to say…
selectValue.onchange = updateCookie;
…while parsing the id as a parameter, i could get this working

[COLOR=“Blue”]
window.onload = init;

//declare selectID as a global variable
var selectID = “”;

function init()
{

//create a variable of all the select tags - this method acts like an array in this instance hence the name
var selectArray = document.getElementsByTagName(‘select’);

for(selectArray[count=0]; count &lt; selectArray.length; count++)
{
	//set selectID and selectCookie variables
	selectID = selectArray[count].id;
	var selectCookie = selectID+"Cookie";
	
	//get the value of the specified cookie
	var selectCookieValue = getCookieValue(selectCookie);
	//set the drop down to show the cookies value
	document.getElementById(selectID).value = selectCookieValue;
	
	//define variable to record the new value of the drop down.
	var selectValue = document.getElementById(selectID);
	//call the function to update cookie
	[COLOR="Red"]selectValue.onchange = updateCookie;[/COLOR]
}

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function getCookieValue(cookieName) {
var thisCookie = document.cookie.split("; ");

for (var i=0; i&lt;thisCookie.length; i++) {
	if (cookieName == thisCookie[i].split("=")[0]) {
		return thisCookie[i].split("=")[1];
	}
}
return 0;

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function updateCookie()
{
//get the new value
updateValue = document.getElementById(selectID).value;
//write the new entry to the cookie
document.cookie = selectID+“Cookie=”+updateValue;

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////[/COLOR]


selectValue.onchange = function() {
    updateCookie(this.value);
}
function updateCookie(val)
{
    document.cookie = selectID+"Cookie="+val;
}

hi, thanks.

i have changed the code to the below, but this is still only recording the last value

[COLOR=“Blue”]window.onload = init;

//declare selectID as a global variable
var selectID = “”;

function init() {

//create a variable of all the select tags - this method acts like an array in this instance hence the name
var selectArray = document.getElementsByTagName('select');

for(selectArray[count=0]; count &lt; selectArray.length; count++)
{
	//set selectID and selectCookie variables
	selectID = selectArray[count].id;
	var selectCookie = selectID+"Cookie";
	
	//get the value of the specified cookie
	var selectCookieValue = getCookieValue(selectCookie);
	//set the drop down to show the cookies value
	document.getElementById(selectID).value = selectCookieValue;
	
	//define variable to record the new value of the drop down.
	var selectValue = document.getElementById(selectID);
	//call the function to update cookie
	//selectValue.onchange = updateCookie;
	
	[COLOR="Red"]selectValue.onchange=function(){updateCookie(selectID);};[/COLOR]
	
	
}

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function getCookieValue(cookieName) {
var thisCookie = document.cookie.split("; ");

for (var i=0; i&lt;thisCookie.length; i++) {
	if (cookieName == thisCookie[i].split("=")[0]) {
		return thisCookie[i].split("=")[1];
	}
}
return 0;

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
function updateCookie(val){
alert(“hi”+val);
updateValue = document.getElementById(val).value;
document.cookie = val+“Cookie=”+updateValue;}

[/COLOR]

if you add…

alert(“hi”+val);

…to updateCookie, you can see the problem.