title: Restrict the input field value of a form to options only
body: <p>I am using a form to insert the value to the database.I want the stationerytype field to insert only the option value.My code allows user to insert the typed value.i dont want to insert this typed value.
  There are two datalist for the option and the value of datalist depends upon the value selected on 'purpose' field. My code is</p>
  <pre><code>&lt;select type=&quot;text&quot; name=&quot;purpose&quot; id=&quot;purpose&quot; class=&quot;form-control&quot; onchange=&quot;random()&quot; required /&gt;
  &lt;option&gt;&lt;/option&gt;
  &lt;option value=&quot;Meeting&quot;&gt;Meeting&lt;/option&gt;
  &lt;option value=&quot;Departmental&quot;&gt;Departmental&lt;/option&gt;
  &lt;/select&gt;
  &lt;/div&gt;
  &lt;script&gt;
    function random() {
      document.querySelector('[name=&quot;stationerytype[]&quot;]').value = &quot;&quot;
      var a = document.getElementById('purpose').value;
      if (a === &quot;Meeting&quot;) {
        var datalist = &quot;datalist1&quot;;
      } else if (a === &quot;Departmental&quot;) {
        var datalist = &quot;datalist2&quot;;
      }
      document.querySelector('[name=&quot;stationerytype[]&quot;]').setAttribute(&quot;list&quot;, datalist)
    }
  &lt;/script&gt;
  &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;stationerytype[]&quot; id=&quot;stationerytype&quot; class=&quot;form-control&quot; autocomplete=&quot;off&quot; required&gt;
    &lt;datalist id=&quot;datalist1&quot;&gt;
      &lt;option value=&quot;&quot;&gt;&lt;/option&gt;
      &lt;option value=&quot;MEETING PEN&quot;&gt;MEETING PEN&lt;/option&gt;
      &lt;option value=&quot;NOTEPAD&quot;&gt;NOTEPAD&lt;/option&gt;
      &lt;option value=&quot;PLASTIC FOLDER&quot;&gt;PLASTIC FOLDER&lt;/option&gt;
    &lt;/datalist&gt;
  
    &lt;datalist id=&quot;datalist2&quot;&gt;
      &lt;option value=&quot;&quot;&gt;&lt;/option&gt;
      &lt;option value=&quot;A4 GREEN REAM&quot;&gt;A4 GREEN REAM&lt;/option&gt;
      &lt;option value=&quot;A4 WHITE REAM&quot;&gt;A4 WHITE REAM&lt;/option&gt;
      &lt;option value=&quot;CELLOTAPE(BROWN)&quot;&gt;CELLOTAPE(BROWN)&lt;/option&gt;
    &lt;/datalist&gt;
  &lt;/td&gt;
  </code></pre>