title: How to use onchange function with a dynamic id that uses brackets
body: <p>I have a php table created by a mysqli query where I want users to be able to update the date values of a text cell. For other formatting reasons, I have chosen not to use the date input. </p>
  
  <p>My script works for other forms with an id that does not include brackets and changes the form value immediately and correctly.  However, when I apply the onchange function to the table cell, it seems the brackets in the id may be holding me up. I can see in the console that I am calling the correct bracketed id, however, nothing else happens. </p>
  
  <p>Here is my cell:</p>
  
  <pre><code>&lt;td&gt;
      &lt;input type='text' class='form-control form-control-sm' 
  id='tbl_date01[".$tbl_ID."]' name='tbl_date01[".$tbl_ID."]' 
  value='".$tbl_date01."' onchange=\"dateChange()\" required /&gt;
  &lt;/td&gt;
  </code></pre>
  
  <p>Here is my script:</p>
  
  <pre><code>function dateChange(){
      var id = (event.target.id);
      var y = document.getElementById(id).value;
      if(y === '?'){
          $("#"+id).val(new Date().toJSON().slice(0,10).substring(5,7) + '/' + new Date().toJSON().slice(0,10).substring(8,10) + '/' + new Date().toJSON().slice(0,10).substring(0,4));
      return;
      };
  };
  </code></pre>