Note that there are some explanatory texts on larger screens.

plurals
  1. POHiding and disabling elements based on a combobox's value with JavaScript
    primarykey
    data
    text
    <p>I have a page where, depending on whether the value of a combobox is false (no), an <code>input</code> box should be hidden and a <code>fieldset</code> disabled. When the combobox's value changes to true (yes), the form should show the <code>input</code> box and enable the <code>fieldset</code>.</p> <p>This is what I have so far:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;combo&lt;/title&gt; &lt;script language="javascript"&gt; function ToggleDisplay(Section, boolHide) { if (boolHide == true) { Section.style.display = "none"; } else { Section.style.display = ""; } } function disableElement(element, boolHide) { var input = document.getElementById(element).getElementsByTagName("input"); for(var i = 0; i &lt; input.length; i++) { input[i].setAttribute("disabled",boolHide); } } function hideShowElement(CurrentSection, OtherSection, DisableSection) { var sectionVal = CurrentSection.value; if (sectionVal == 0) { ToggleDisplay(OtherSection, true); //disableGroup (this.form, 'Radio1' , true); disableElement(DisableSection, "true"); } else { ToggleDisplay(OtherSection, false); //disableGroup (this.form, 'Radio1' , true); disableElement(DisableSection, "false"); } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form name="testForm" action="" method="post"&gt; Show Hidden Text? &lt;select name="cmbYN" onchange="hideShowElement(this, MyDIV, 'OptionGrp1');"&gt; &lt;option value="0" selected="selected"&gt;&lt;/option&gt; &lt;option value="1"&gt;Yes&lt;/option&gt; &lt;option value="0"&gt;No&lt;/option&gt; &lt;/select&gt; &lt;div id="MyDIV" style="display: none"&gt; My Hidden Text: &lt;input name="Text1" type="text" /&gt; &lt;br&gt; &lt;/div&gt; &lt;fieldset id="OptionGrp1" name="Group1"&gt; Option Group&lt;br&gt;&lt;br&gt; Option 1&lt;input name="Radio1" type="radio" checked&gt; Option 2&lt;input name="Radio1" type="radio"&gt; &lt;/fieldset&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This is hiding the <code>input</code> box and disabling the <code>fieldset</code>, but not re-enabling them.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload