in the code below $firstSelect and $secondSelect contain the names of select fields in the form someForm. I am needing to use the name of the second select field in the function. where there is a :confused: i need a reference to the name of the second select field

<select name="<? echo $firstSelect ?>" onChange="makeFirstOptionNull(<? echo $secondSelect ?>)"></select>
<select name="<? echo $secondSelect ?>"></select>
this is an example that doesn't work. what doesn't make sense to me is that when i do a document.writeln(selObj); instead of what is in the function. the output is

[object]

if I change to document.writeln(selObj.name); it displays

secondSelect1

In the function i want the equivalent of
document.someForm.secondSelect1.options.value = null;

tater

06-23-2004, 10:19 PM

ive looked at it some more and i know what im unable to do

say i have a variable
var junk= "fieldname";

how do i execute

document.someform.fieldname.options.value = null;

using junk

this doesn't work
document.someform.junk.optioins.value = null;

Roy Sinclair

06-23-2004, 10:54 PM

Two words: Bracket Notation.

The Bracket Notation method will take care of you:

var junk = "fieldname';

document.forms.formname.elements[junk].options.value = null;

or

document.forms["formname"].elements[junk].options.value = null;

Please note that you can leave out the ".forms" part of the first reference above but it's more correct to properly direct the lookup to the forms array and in a tight loop that's executed a lot of times there will be an appreciable performance difference.

tater

06-23-2004, 11:15 PM

thank you

that was what i needed to know

why does it pass a varible to a function as an object
for instance in a function i had to use the .name
example..

function makeFirstOptionNull( selObj )
{
document.someForm.elements[selObj.name].options.value = null;
document.someForm.submit();
}
the code above worked but i still don't understand why the passed variable is an object

glenngv

06-24-2004, 05:48 AM

Since you already pass the select object reference to the function, you can use it directly without going through the form object again.