0

I am trying to create a site where you select an option from a dropdown list called contactOptions. The options has values ranging from 0 to 8. When the option is selected, I wish for text to appear underneath -- this text is contained within div tags with ID's such as #contact0 for the text corresponding to option 0. These ID's all have display: none by default. I have some JavaScript (below) -- the select tag in my html includes the line onchange = "sortForm()". Unfortunately, the script does not do anything -- the #contact0 remains invisible.

function sortForm() {
  var selection = document.getElementById("contactOptions");
  var selectedValue = selection.options[selection.selectedIndex].value;

  for (var i = 0; i <=8; i++) {
    var subobjContact = document.getElementById("contact" + i);
    if (i == selectedValue) {
      subobjContact.style.display == "block"
    } else {
      subobjContact.style.display == "none"
    }
  }
}

1 Answer 1

1

Use single equal sign

subobjContact.style.display = "block"

and

subobjContact.style.display = "none" 
Sign up to request clarification or add additional context in comments.

1 Comment

I'll accept that as soon as I can, need to wait 8 mins. Thank you -- so annoying when you comb the code and it turns out to be something so stupid like that. cry

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.