Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-12-2008, 04:31 AM   PM User | #1
chikna
New Coder

 
Join Date: Nov 2007
Posts: 71
Thanks: 9
Thanked 0 Times in 0 Posts
chikna is an unknown quantity at this point
Small script - bugging me?

<body>
<script type="text/javascript">
var name = "john";
var a = (name=="jOhn") ? "true" : "false";

if (a) {
alert(a);
}

</script>

</body>

for both true or false conditions, I get an alert message. Variable a is "false". What is wrong? I want to process only when condition is true. How can I achieve this different way? Thanks.
Edit/Delete Message
chikna is offline   Reply With Quote
Old 01-12-2008, 04:41 AM   PM User | #2
raghu207
New Coder

 
Join Date: Aug 2006
Posts: 54
Thanks: 3
Thanked 0 Times in 0 Posts
raghu207 is an unknown quantity at this point
In your condition:
var a = (name=="jOhn") ? "true" : "false";

You have used "true" : "false". Both of these are string and not boolean variables which i think you intended.. Thats why javascript is showing the alert.

Replace the strings with booleans and its done.
var a = (name=="jOhn") ? true : false;
raghu207 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:24 AM.


Advertisement
Log in to turn off these ads.