<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
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;