0

How to hide if the input text is null. this are my script code

             $(document).ready(function(){
              var taena = document.getElementById("no2").value;

                  if (taena === "") {
                      $('#hideall').hide();

                  else{
                      $('#hideall').show();
                  }
                  });
4
  • Looks like your code should work provided that ids like no2 and hideall must be unique in html file Commented May 5, 2016 at 9:05
  • What is the id of your div? Commented May 5, 2016 at 9:05
  • 4
    You're missing a brace in the if/else statement Commented May 5, 2016 at 9:05
  • omg! lol. sorry my eye sight is getting weaker. thanks bro. Commented May 5, 2016 at 9:07

1 Answer 1

3

You can rather trim out spaces from returned value and check for length and then do show hide decision based on it:

$(document).ready(function(){
  $('#hideall').toggle($("#no2").val().trim().length > 0);
});
Sign up to request clarification or add additional context in comments.

1 Comment

@PranavCBalan: you are right :) . i need to add the check for bool here. thanks again

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.