Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I want to hide a list column in editform.aspx

</script>
<script language="JavaScript">
$(document).ready(function() 
{ $('nobr:contains("columnname")').closest('tr').hide()  });
</script>

It works. But now I want to hide it, if there is no value. How to do this?

share|improve this question
    
You should be able to get the content using jquery val() on the input element then hide if val() == "" –  Luis Jul 17 '13 at 12:04

2 Answers 2

up vote 1 down vote accepted
$(document).ready(function() 
{ if ($('nobr:contains("columnname")').val() == "")
  {
    $('nobr:contains("columnname")').closest('tr').hide()
  }  
});
share|improve this answer
<script language="JavaScript">
$(document).ready(
  function() 
  {  
   // Creating an object to reduce JQuery selector to get the same element again
   // which reduces a considerable lines of code being interpreted from JQuery lib
   // which is expensive operation than having a reference object in hand.
   var myElement = $('nobr:contains("columnname")'); 

   // since they typeof(myElement.val().length) is number, 
   // you can use === conditional operator.
   // '===' is faster. The reason being, that it only needs to compare the type,
   // and if that matches, compare the raw data.
   // The == operator will try to convert one type to another if they don't match.
   // This will be a more expensive operation in most cases.
   if(myElement.val().length === 0)  //or if(myElement.val() === "")
   {
    myElement.closest('tr').hide();
   }
  }
);
</script>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.