title: TypeError: document.getElementById(...) is null in javascript
body: <p>This is my coding for dynamic field validation.
  if i use this function i got 'TypeError: document.getElementById(...) is null' this kind of error.</p>
  
  <pre><code>function sr_answer_val(){
    var cnt=parseInt(document.getElementById("add_field_cnt").value);
    var submitAllow=true;
    for(var i=1;i&lt;cnt;i++){
      if(document.getElementById("cust_field_"+i).value ==''){
        alert('Answer Should be Mandatory');
        submitAllow=false;
        return false;     
      }
    }
  }
  </code></pre>