Click to See Complete Forum and Search --> : pass a string to build an object call


jsrules
08-19-2005, 03:45 PM
I'm trying to pass a text string to a function then use that string to build a variable and assign an object to it.

This alerts the word undefined
function clearSelection(listName){
var form = document.appForm.listName;
alert(form);

}
clearSelection('webServer');

This alerts the text "document.appForm.webServer"
function clearSelection(listName){
var form = "document.appForm." + listName;
var obj = form;
alert(obj);

}
clearSelection('webServer');

If i call on the object correctly i would expect the word [object] to be alerted.
How can i pass a text string and attach it to an object call??

Ultimater
08-19-2005, 04:04 PM
function clearSelection(listName){
var form = document.appForm.listName;
alert(form);

}

document.appForm[listName]

jsrules
08-19-2005, 04:12 PM
Thank you! That worked...