0

I want to show and hide a div based on a condition. Please help me do this. This my code:

<script> 
  var shad = '{SUBJECT}';       
  if (shad != "") {
    document.getElementById("subjectr").style.display = 'none';
  } else {
    document.getElementById("subjectr").style.display = 'show';
  }
</script>

<div  id="subjectr">
  sub
  <input type="text" name="subjectr">
</div>
4
  • 3
    add ID in you input code <input type="text" name="subjectr" id="subjectr"> Commented Mar 20, 2017 at 10:40
  • 1
    possible duplicate stackoverflow.com/questions/21070101/… Commented Mar 20, 2017 at 10:41
  • i want to show and hide div without write any function ..it is possible??please correct my above code..@Kapila Perera Commented Mar 20, 2017 at 10:43
  • show is not a valid value of display It should be block or inline-block Commented Mar 20, 2017 at 10:46

2 Answers 2

2

Try the following:

var shad ='SUBJECT';      
if (shad !="") {
  document.getElementById("subjectr").style.display = 'none';
}
else {
  document.getElementById("subjectr").style.display = 'block';
}
sub: <input type="text" name="subjectr" id="subjectr" value='SUBJECT'/>

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

Comments

1
  var shad ='SUBJECT';        
  if (shad != "") {
    document.getElementById("subjectr").style.display = 'none';
  } else {
    document.getElementById("subjectr").style.display = 'block';
  }

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.