Javascript, add new entry to dialog list via passed fieldname object question

Can I pass to name of a dialog list field in javascript to add a new entry. Below is some code I have to add a new entry to a dialog list, the commented part, axletype is the dialog list field name. The commented code works but I want to do something generic by passing the fieldname. In my uncommented code I get an error options is null or not an object, can anyone point me in the right direction, thanks…

function addNewDialogEntry(fieldName) {

var newValue = prompt("Enter new value","");

var frm = document.forms[0]

if(typeof newValue == "string") {

	//var tmpFieldName = frm.axletype;

	//tmpFieldName.options[tmpFieldName.length] = new Option(newValue, newValue, true, true)

	fieldName.options[fieldName.length] = new Option(newValue, newValue, true, true)

}

}

Subject: Javascript, add new entry to dialog list via passed fieldname object question

If you are passing the name of the field, you need to find the corresponding

Subject: RE: Javascript, add new entry to dialog list via passed fieldname object question

Thanks Stan, I added the completed code below for everyones reference.

function addNewDialogEntry(fieldName) {

var newValue = prompt("Enter new value","");

var frm = document.forms[0]

if(typeof newValue == "string") {

	var tmpFieldName = frm.elements[fieldName];

	tmpFieldName.options[tmpFieldName.length] = new Option(newValue, newValue, true, true)

}

}

one of my original problems was using frm.elements[fieldname];

oh, well