JavaScript and client side scripting.
Moderator: General Moderators
Lphp
Forum Commoner
Posts: 74 Joined: Sun Jun 26, 2011 9:56 pm
Post
by Lphp » Sun Sep 23, 2012 10:56 pm
I have for loop inside tee if else
Code: Select all
if((document.fac.type[2].checked==true)||(document.fac.type[3].checked==true) ){
for (var i=1;i<=6;i++)
{
document.fac.category[i].disabled=true
document.fac.name[i].disabled=true
document.fac.post[i].disabled=true
}
}
i keep get error
Uncaught TypeError: Cannot read property '1' of undefined point to the for loop, what stupid mistake that I made?
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Sep 24, 2012 1:13 am
document.fac.category, document.fac.name, and/or document.fac.post are undefined. Make sure you're looking at the right objects/arrays in the right places.
Lphp
Forum Commoner
Posts: 74 Joined: Sun Jun 26, 2011 9:56 pm
Post
by Lphp » Mon Sep 24, 2012 3:57 am
but the following hard code work fine
document.fac.category1.disabled=false
document.fac.name1.disabled=false
document.fac.post1.disabled=false
requinix
Spammer :|
Posts: 6617 Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA
Post
by requinix » Mon Sep 24, 2012 5:57 am
That's great and all but category and category1 are two different things.
Fortunately JavaScript is flexible when it comes to object members.
Lphp
Forum Commoner
Posts: 74 Joined: Sun Jun 26, 2011 9:56 pm
Post
by Lphp » Mon Sep 24, 2012 9:12 pm
thanks a lot