1

When the document loads I am trying to css hide a check box only if a textbox has text. Instead all the check boxes are being hidden, even if the text boxes are empty. Any help please

    $(document).ready(function () {


            //if statements to disable the fill checkboxes if there are dates already filled
            if ($("#<%=FinishDateSrvcTXT.ClientID%>").text != "") {
                $("#<%=FinishFillCHK.ClientID%>").css('display', 'none');
            }

            if ($("#<%=startdateSrvcTXT.ClientID%>").text != "") {
                $("#<%=StartFillCHK.ClientID%>").css('display', 'none');
            }

            if ($("#<%=FinishDateBodyShopTXT.ClientID%>").text != "") {
                $("#<%=FillFinishBodyShopCHK.ClientID%>").css('display', 'none');
            }
            if ($("#<%=StartDateBodyShopTXT.ClientID%>").text != "") {
                $("#<%=FillStartBodyCHK.ClientID%>").css('display', 'none');
            }
            if ($("#<%=CompleteDatedetailTXT.ClientID%>").text != "") {
                $("#<%=CompleteFilldetailCHK.ClientID%>").css('display', 'none');
            }

            if ($("#<%=startdatedetailtxt.ClientID%>").text != "") {
                $("#<%=startdatedetailCHK.ClientID%>").css('display', 'none');
});
2
  • use .val() insead of .text Commented Jan 7, 2012 at 22:35
  • how do you define "text"? is this the value? the text after the input type checkbox? You use <input></input>? a label? Commented Jan 7, 2012 at 22:36

3 Answers 3

1

Hm, try

 function check() {
 if(document.getElementById('yourTextFieldId').text != null) {
 document.getElementById('yourCheckboxId').disabled = true;
 }
 else {
 document.getElementById('yourCheckboxId').disabled = false;
 }
 }
Sign up to request clarification or add additional context in comments.

Comments

1

you can use something like this:

$('input:checkbox').each(function () {
    if (!this.value || !$(this).text() ) $(this).hide();
});

here it will hide each checkbox as soon as there is no value or no text.

Comments

0

Change your if statements to use val().

$("#<%=FinishDateSrvcTXT.ClientID%>").val().length > 0){
   $("#<%=FinishFillCHK.ClientID%>").css('display', 'none');
}

1 Comment

Noticed it just before you commented :D. Essentially, you use val() to get the value in the textbox instead of text.

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.