title: Set a field to required in html when an option is selected
body: <p>Hi I am trying to make a field required when option is selected like if option 1 is selected so field one will be required and if option 2 then field 2 and make field 1 not required so on. So far I have tried setAttribute, removeAttribute, getelemenybyid(..).required=true or false (proper camel cases are used in code). nothing seem to work.to better explain I have entered the code below. I am using this form as Camunda embedded form and scripts are java scripts. smaple below</p>
  <pre><code>&lt;div class=&quot;form-group&quot; &gt;
    &lt;label for=&quot;AmendmentType&quot; &gt;Amendment Type: &lt;/label&gt;
  &lt;select class=&quot;form-control&quot; onchange=&quot;Optionselection(this);&quot; cam-variable-name=&quot;AmendmentType&quot; cam-variable-type=&quot;String&quot; id = &quot;AmendmentType&quot; required&gt;
    &lt;option onClick=&quot;Optionselection()&quot; id=&quot;update&quot; name=&quot;AmendmentType&quot; value=&quot;Update a field&quot;&gt;Update a field&lt;/option&gt;
    &lt;option onClick=&quot;Optionselection()&quot; id=&quot;DuplicateId&quot; name=&quot;AmendmentType&quot; value=&quot;Duplicate Tax Files (to be mande inactive)&quot;&gt;Duplicate Tax Files (to be made inactive)&lt;/option&gt;
  &lt;/select&gt;
    &lt;/div&gt;
  </code></pre>
  <pre><code>function Optionselection(that) {
     if (that.value == &quot;Update a field&quot;) {
          document.getElementById('ValueinSystem').required=true;
          document.getElementById('duplicateID').required=false;
  }
     else if(that.value == &quot;Duplicate Tax Files (to be mande inactive)&quot;) {
          document.getElementById('ValueinSystem').required=flase;
          document.getElementById('duplicateID').required=true;
  
  }       
  </code></pre>
  <p>as i said i tried the following nothing seems to work</p>
  <pre><code>function Optionselection(that) {
     if (that.value == &quot;Update a field&quot;) {
          document.getElementById('ValueinSystem').setAttribute('required','');
          document.getElementById('duplicateID').removeAttribute('required');
  }
     else if(that.value == &quot;Duplicate Tax Files (to be mande inactive)&quot;) {
          document.getElementById('duplicateID').setAttribute('required','');
          document.getElementById('ValueinSystem').removeAttribute('required');
  
  }
  </code></pre>