• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

HTML - How to hide a Div tag or other tag

Kelemvor

Lifer
I have a form that has a dropdown menu and some text boxes. One of the text boxes doesn't apply to some of the dropdown items.

I want a way that if a certain dropdown item is selected, one of the text boxes will hide.

I know I can just set the actual text box to hidden but I want to hide the text description of the box as well.

I know I can hide a DIV tag but what is the easiest way to do that? It;s one specific tag with a specific ID. Can this be done with one line such as an onSelect command to just hide the one tag? Or is there another easier way to do this maybe?

Thanks.
 
I do this sort of thing in a web application I'm working on.

Markup:

<select name="ddDropDown" id="ddDropDown" onchange="DoFunction(this);">
....<option value="1">One</option>
....<option value="2">Two</option>
....<option value="3">Three</option>
</select>
<div id="divControls">
....<p><input type="text" name="name" id="name" /></p>
</div>

JavaScript:
function DoFunction(ddDropDown) {
....var selIndex = ddDropDown.selectedIndex;
....var selValue = ddDropDown.options[selIndex].value;

.... // hide div if selected item is "Two"
....if (selValue == "2") {
........var divControls = document.getElementById('divControls');
........divControls.style.display = 'none';
........// or: divControls.style.visibility: 'hidden';
....}
}

.style.display: none -- Control will not be visible and any contents around it will move around it as if it wasn't on the page
.style.visibility: hidden -- Control will not be visible but controls around it will stay in place as if it were there
 
Yeah jQuery is something to look into. I've started using it on my personal website and it's frickin great.
 
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.

In my opinion, it is javascript the way it was meant to be done.
 
Originally posted by: sourceninja
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript.

In my opinion, it is javascript the way it was meant to be done.

Man speaks the truth.

John Resig is my hero.
 
I ended up just using a script that concluded with:

document.getElementById(item).style.display = flag; where flag was either None or Block
 
Back
Top