I don't why this is not working. Can somebody tell me what is the problem with this?
var x = $('#clicked_info').val(); if(x == 1) { $('#companyname_ph').css({'color':'yellow'}); } else if(x == 2) { $('#companyname_ph').css({'color':'red'}); } You need to use parseInt to convert a string to an integer.
var x = $('#clicked_info').val(); if(parseInt(x) == 1){ $('#companyname_ph').css({'color':'yellow'}); } else if(parseInt(x) == 2){ $('#companyname_ph').css({'color':'red'}); } OR use string comparison
if(x == '1'){ === comparison operator instead of ==.'1' == 1 it return false. You don't need to write '1' === 11 == '1' :)val returns a string
x == 1 shoulb be x == '1'
x == 2 should be x == '2'
Or you can convert x to int using the following.
var x = $('#clicked_info').val(); x = parseInt(x); 1 == '1'. This shouldn't matter.like the other folks here have noted, you should use parseInt when you want to convert a string representation of an integer to a number type. I would add that you should provide a radix to parseInt because if you don't, you may get unexpected results if your string starts unexpectedly with "0x" :)
try doing:
var x = parseInt($('#clicked_info').val(), 10) 0x (hexadecimal), you'll also get unexpected results if your string begins with 0 (octal), which is far more common than 0x.
#clicked_info? Are you sure it contains either1or2?<input>, or something else? A wild guess: if you're trying to get the text content, use.text(), not.val().