/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] if statement true when false?

I have here menu that pop ups or vanishes when the enter key is pressed.
when i set an alert, the alert constantly say that the menu changed to inline even when it wasn’t inline before?

[code]function checkKey(event)
{
if (event.keyCode==13)
{
if (document.getElementById(‘menu’).style.display=’none’)
{
document.getElementById(‘menu’).style.display=’inline’;
}
else
{
document.getElementById(‘menu’).style.display=’none’;
}
}
}[/code]

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERJan 16.2009 — The key pressed event is handled differently by different browsers.

Which one are you using or have you tried in more than one?

Do you have more code that post #1?
Copy linkTweet thisAlerts:
@MrNobodyJan 16.2009 — This is faulty:
[CODE]if (document.getElementById('menu').style.display='none')[/CODE]
should be:
[CODE]if (document.getElementById('menu').style.display=='none')[/CODE]
Copy linkTweet thisAlerts:
@Hud4007authorJan 16.2009 — Thanks for replying
The key pressed event is handled differently by different browsers.

Which one are you using or have you tried in more than one?

Do you have more code that post #1?[/QUOTE]
I want it to be useable in the wii opera browser, but currently i tried it in google chrome and FF

and code?

herediv#menu {display:none;}
#display {border-style:solid;border-width:1px;border-color:black;z-index:2;background-color:white;width:100%;height:100%;width:50%;height:50%;position:absolute;top:25%;left:25%;}
#bg {z-index:1;opacity:0.5;background-color:black;width:100%;height:100%;margin:0px;position:absolute;top:0px;left:0px;}
.item {margin:5px;text-align:center;}
#tip {position:absolute;bottom:0px;right:0px;}



function onload()
{
c=1
}



<body onload="onload();" onkeypress="checkKey(event);" style="margin:0px;">
<div id="codedbrowser">
<div id="menu">
<div id="bg"></div>
<div id="display">
<span class="item">Main Menu</span><hr />
<span class="item" id="tip">Press (1) to Exit Menu</span>
</div>
</div>
</div>
</body>
also the (1) business, the unicode i think is 172,c is to signify that the onload function occured and was finishedThis is faulty:
[CODE]if (document.getElementById('menu').style.display='none')[/CODE]
should be:
[CODE]if (document.getElementById('menu').style.display=='none')[/CODE][/QUOTE]
this makes nothing happen no alert, no appearance
Copy linkTweet thisAlerts:
@MrNobodyJan 16.2009 — this makes nothing happen no alert, no appearance[/QUOTE]
Nevertheless ... The syntax needed correction. I wasn't addressing your logic. When testing for equality, you can't have such a condition test in an IF statement without using the double equal sign. A single equal sign is always an assignment and, thus, the only condition will be the result of the assignment -- which is almost always considered a [B]true[/B] result. Thus, the [B]else[/B] statement will never execute.
Copy linkTweet thisAlerts:
@Hud4007authorJan 16.2009 — i now understand MrNobody

in my code i must have put ELSE [b]IF (...)[/b] instead of else and edit them differently than i stated, sorry on my part, he solved my problem

Yay its solved!!!?
×

Success!

Help @Hud4007 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 5.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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