Is Null or Not an OBJECT

M

Michael Hill

I created this select dynamically in a page like:

var j=4;
mySELECT = document.createElement("SELECT");
mySELECT.name = "MEMBER" + j;
mySELECT.onclick = function (evt) { alert(this.name); }
myOPTION = document.createElement("OPTION");
myOPTION.value="1";
myTEXT=document.createTextNode("first");
myOPTION.appendChild(myTEXT);
mySELECT.appendChild(myOPTION);
myOPTION = document.createElement("OPTION");
myOPTION.value="2";
myOPTION.selected="true";
myTEXT=document.createTextNode("second");
myOPTION.appendChild(myTEXT);
mySELECT.appendChild(myOPTION);
myTD.appendChild(mySELECT);

But then when I try to access it with either:

document.update.elements['MEMBER4'].value

or

document.update.MEMBER4.value

or

document.update.elements['MEMBER4'].options[document.update.elements['MEMBER4'].selectedIndex].text;

I get blah, blah ... 'is null or not an object'.

I can see the object on the page and when I click on it I get the alert
message showing the name is "MEMBER4".

I am stumped why I am getting this message. Something must not be right.
Could it be that it is not getting created in the form "update"? I need
to have it created there.

Any help is appreciated.

Mike
 
M

Michael Hill

Could it be that it is not getting created in the form "update"? I need
to have it created there.

Naw, it is being created in the <form> heirarchy.....
 
D

Dominique

try document.all.item("MEMBER4").value

if this works, then it obviously isn't being created inside the form
"update"
:eek:)
 
R

Randy Webb

Dominique said:
try document.all.item("MEMBER4").value

if this works, then it obviously isn't being created inside the form
"update"
:eek:)

And then it only works in IE and perhaps Opera, since document.all is
IE-ism.
 
D

Dominique

lol* i didn't give you that to solve yer problem, i gave it to you to check
whether you CAN find the object

try this, add an ID attibute to it and call it by the getElementById (not
IE-ism) method
 
R

Randy Webb

Dominique said:
lol* i didn't give you that to solve yer problem, i gave it to you to check
whether you CAN find the object

try this, add an ID attibute to it and call it by the getElementById (not
IE-ism) method

Now you are making the mistake of assuming I am the one that posted the
original question. Perhaps if you spent as much time trying to learn
what you were doing, you would not be wasting as much time giving
incompetent answers.
 
D

Dominique

oh fukkoff randy

try giving a frikkin answer for once instead of giving snide remarks when
we're trying to help people here.

and sorry for not checking ur stoopid name in that last post, i'm busy
actually HELPING PEOPLE in other groups.

yer yapping and not helping, so just log off and go eat yer dinner, fukkin
prick.

and write better faq's on that crap website. learn some actual programming
skills, not theory.
 
M

Michael Hill

Dominique said:
lol* i didn't give you that to solve yer problem, i gave it to you to check
whether you CAN find the object

try this, add an ID attibute to it and call it by the getElementById (not
IE-ism) method

When I changed this:

mySELECT.name = "MEMBER" + j;

to this:

mySELECT.id = mySELECT.name = "MEMBER" + j;

if worked fine.

Thanks for the reminder.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top