Basic Javascript problem

  • Thread starter Thread starter Eldon Ferran de Pol
  • Start date Start date
E

Eldon Ferran de Pol

Hi all,

Can anyone see what is wrong with this function. It's
being called by the OnClick of a radio button. For some
reason I can't access the options collection or any of the
Select's basic properties (e.g. type, name etc.). I've
tried access ddlMonEnd using this syntax as well as
GetElementByID and doc.frm.ddlMonEnd. None of them work
for me.

function SetWeekdayServiceTimes(intStartIndex,intEndIndex)
{
alert(document.getElementsByName
('ddlMonEnd').options.selectedIndex);
}
 
Are you sure that the Control you're referencing has that name in the page?
First, did you assign a name attribute to it? If so, check the HTML on the
client side (in the browser). ASP.Net renames client-side objects sometimes
in order to ensure that they have unique values.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Obviously getElementsByName() returns a collection so you
would need to do something like this
document.getElementsByName('ddlMonEnd')
[0].options.selectedIndex to get the select object...
(i'm not really sure this kind of syntax is correct in
javascript, it is in C#.. if it doesnt work put the
collection in a variable and then index into it)

anyway, it is easier to access an object with
getElementById as it only returns one object, not
collection...
im not sure about netscape, but in IE to access an object
you can just use its ID like if you object has the id
ddlMonEnd just alert(ddlMonEnd.options.selectedIndex)...
you can also do alert
(document.formname.ddlMonEnd.options.selectedIndex)..
there are many ways to access it and you picked a pretty
wierd one :) maybe you have your reasons though
 
Back
Top