0

i am checking certain condition in documnet.ready and && operator is not working code snippet lblvalue is empty.

$(function () {
 var lblValue = $("#lblRadioText").text();
    if (lblValue.length > 0 && hasWhiteSpace(lblValue) > 0) {
        $("#rdExportLastTime").css('display', 'inline');
    }
});

function hasWhiteSpace(text) {
    return text.indexOf(' ') >= 0;
}

can you tell me what is wrong.

2
  • 1
    try if ((lblValue.length > 0) && (hasWhiteSpace(lblValue) > 0)) { so that both statements are enclosed within their own parentheses. Commented Nov 25, 2011 at 10:31
  • try this ...if (lblValue.length > 0 && (hasWhiteSpace(lblValue) > 0)) { Commented Nov 25, 2011 at 10:32

3 Answers 3

4

You are trying to check if your boolean value is great than 0.

You don't need the 2nd > 0:

if (lblValue.length > 0 && hasWhiteSpace(lblValue)) {
    $("#rdExportLastTime").css('display', 'inline');
}

Actually, that doesn't make any difference to the operation but it's still not needed.

The code seems to work fine to me (slightly adapted for testing): http://jsfiddle.net/infernalbadger/ZGAj5/1/

Sign up to request clarification or add additional context in comments.

Comments

3

You're returning a boolean value out of hasWhiteSpace(), so you should skip the > 0 in your conditional.

Comments

0

Are you sure that it is operator && that fails?

What if you rewrite your code to:

var lblNotZero = lblValue.length > 0;
var hasWhiteSpace = hasWhiteSpace(lblValue) > 0;
if(lblNotZero && hasWhiteSpace)
{
  $("#rdExportLastTime").css('display', 'inline');
}

Now set a breakpoint (or output using alert) to check the values of lblNotZero and hasWhiteSpace.

Whenever you suspect language fundamentels such as && not working correctly, rethink. Those are extremely well tested.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.