/    Sign up×
Community /Pin to ProfileBookmark

Problem disabling drop downs.

Hello,
I am new to javascript and have what i think is a really simple problem. I have a few drop downs that I want to disable via javascript.

[code]
var x = $get(‘currentEventInputSelect’).value;
if (x == 4)
{
$get(name_dropDownListControl’).disabled=true;
$get(address_dropDownListControl’).disabled=true;
$get(age_dropDownListControl’).disabled=true;
}
[/code]

It will only work if I put this before the if:

[code]
alert(x);
[/code]

can anyone please explain to me why this happens. I am using VS 2005 C# and the above code is being called in the

[code]
function pageLoad(sender, args)
{

{
[/code]

Thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@toicontienMar 14.2008 — You have some syntax errors:
var x = $get('currentEventInputSelect').value;
if (x == 4)
{
// Missing the opening single quotes
$get('name_dropDownListControl').disabled=true;
$get('address_dropDownListControl').disabled=true;
$get('age_dropDownListControl').disabled=true;
}
Copy linkTweet thisAlerts:
@smithsf22authorMar 14.2008 — Yeah sorry about that... in my code it does have the single quotes ?, but still have the problem
Copy linkTweet thisAlerts:
@toicontienMar 14.2008 — What is the $get function? Is it a wrapper for document.getElementById()?

Lastly, are 'currentEventInputSelect', 'name_dropDownListControl', 'address_dropDownListControl', 'age_dropDownListControl' all HTML tag Ids? And are they they only instances of those Ids on your whole page?

Does this code work?
var x = Number(document.getElementById('currentEventInputSelect').value);
if (x == 4)
{
document.getElementById('name_dropDownListControl').disabled = true;
document.getElementById('address_dropDownListControl').disabled = true;
document.getElementById('age_dropDownListControl').disabled = true;
}
×

Success!

Help @smithsf22 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.1,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...