469,951 Members | 2,487 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,951 developers. It's quick & easy.

Is Null or Not an OBJECT

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
Jul 23 '05 #1
7 5012
> 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.....
Jul 23 '05 #2
try document.all.item("MEMBER4").value

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

"Michael Hill" <hi****@ram.lmtas.lmco.com> wrote in message
news:40***************@ram.lmtas.lmco.com...
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['MEMBER
4'].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

Jul 23 '05 #3
Dominique wrote:
try document.all.item("MEMBER4").value

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


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

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #4
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

"Randy Webb" <hi************@aol.com> wrote in message
news:L5********************@comcast.com...
Dominique wrote:
try document.all.item("MEMBER4").value

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


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

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 23 '05 #5
Dominique wrote:
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

"Randy Webb" <hi************@aol.com> wrote in message
news:L5********************@comcast.com...
Dominique wrote:

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

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


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


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.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/
Jul 23 '05 #6
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.
"Randy Webb" <hi************@aol.com> wrote in message
news:Ma********************@comcast.com...
Dominique wrote:
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

"Randy Webb" <hi************@aol.com> wrote in message
news:L5********************@comcast.com...
Dominique wrote:
try document.all.item("MEMBER4").value

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

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


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.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 23 '05 #7


Dominique wrote:

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
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by RMD | last post: by
99 posts views Thread by Mikhail Teterin | last post: by
5 posts views Thread by David Sworder | last post: by
2 posts views Thread by Jongmin | last post: by
64 posts views Thread by yossi.kreinin | last post: by
3 posts views Thread by toton | last post: by
46 posts views Thread by lovecreatesbea... | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.