/    Sign up×
Community /Pin to ProfileBookmark

small function not working

Hello all,
I’m a php coder and i need to have a really simple function in javascript , i googled around and built a small function but i doesnt seem to be working ?

Please give me a hand

[code]
function disable(i) {
if(“distro1.”+ i +”.disabled” == false){
“distro1.”+ i +”.disabled “= true;
} else {
“distro1.”+ i +”.disabled “= false;
}
}
[/code]

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@konithomimoNov 12.2005 — well, without knowing what distro1 and i are I can't help much, but I can tell you that you need to use getElementById or getElementByName in javascript. You cannot just call an object by its name. Tell us what I and distro one are and then we can help.
Copy linkTweet thisAlerts:
@JPnycNov 12.2005 — Doesn't matter what it is, you can't reference any page element like that. You have to reference the DOM.
Copy linkTweet thisAlerts:
@djpateauthorNov 12.2005 — hello guys

distro1 is the name of the form

and i is the name of a drop down box

i dont understant what you mean by DOM
Copy linkTweet thisAlerts:
@konithomimoNov 12.2005 — function disable(i)

{

if(document.getElementByName(i).disabled == false)

{

document.getElementByName(i).disabled= true;

}

else

{

document.getElementByName(i).disabled= false;

}

}
Copy linkTweet thisAlerts:
@djpateauthorNov 12.2005 — thanks for your help !

Now i get an error saying the object doesnt support this property or method
Copy linkTweet thisAlerts:
@konithomimoNov 12.2005 — Then give your drop down box and ID

id="dropdown1"

and then do:
<i>
</i>function disable(i)
{
if(document.getElementById(i).disabled == false)
{
document.getElementById(i).disabled= true;
}
else
{
document.getElementById(i).disabled= false;
}
}


and make sure that disabled is an attribute of the drop down list.
Copy linkTweet thisAlerts:
@konithomimoNov 12.2005 — Which it is, so just use getElementById()
×

Success!

Help @djpate spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...