0
var test = document.getElementById("TEST1").value; if (test.value != 1) { document.getElementById("field_DOPT").style.display='none'; } 

This doesn't seem to work. I am getting the TEST1 value as 1 but its not hiding the div. Any help will be appreciated. thank you

3 Answers 3

1

In your case test is the value of the input element TEST1, it doesn't have a value property

so either assign the element as the value to test then use test.value in your condition

var test = document.getElementById("TEST1"); if (test.value != 1) { document.getElementById("field_DOPT").style.display='none'; } 

or use just test in the condition

var test = document.getElementById("TEST1").value; if (test != 1) { document.getElementById("field_DOPT").style.display='none'; } 
Sign up to request clarification or add additional context in comments.

Comments

0

You have assigned TEST1 value to the test variable, so in test you have do:

if (test != 1) { document.getElementById("field_DOPT").style.display='none'; } 

Comments

0

You already get the value property of your element when you define test, and then you look for the value property of its value property - so the simplest way to improve this code is:

var testValue = document.getElementById("TEST1").value; if (testValue != 1) { document.getElementById("field_DOPT").style.display='none'; } 

I've changed your variable name from test to testValue so that it's clear that you are not actually dealing with the TEST1 element but instead with its value (so that it is clear there is no need to get the value property.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.