title: How to pass form name to javascript and use it to read form values
body: <p>I wanted to know how to pass the form name dynamically and use it to retrieve form values. I used the below code.</p>
  
  <pre><code>function validatecbr(form,outagetkt)
  {
  
      var formName = form.name;
      alert(formName);
  
      var cbr1 = formName.cbr11.value;
      var cbr2 = formName.cbr22.value;
      var cbr3 = formName.cbr33.value;
      var cbrnum = cbr1+cbr2+cbr3;
      if(cbr1.length !=3){
          alert("Please Enter 10 digit Account telephone number");
          formName.cbr11.focus();
          return false;
      }
      else if(cbr2.length !=3){
          alert("Please Enter 10 digit Account telephone number");
          formName.cbr22.focus();
          return false;
      }
      else if(cbr3.length !=4){
          alert("Please Enter 10 digit Account telephone number");
          formName.cbr33.focus();
          return false;
      }
      else
      {
          alert("cbrnum "+cbrnum);
  
          formName.method="POST";
          formName.action="/support/residential/outage/serviceOutage?cbrnum="+cbrnum+"&amp;btn="+btn+"&amp;outagetkt="+outagetkt;
          formName.submit();
      }
  }
  </code></pre>
  
  <p>The below is the body content</p>
  
  <pre><code>&lt;body&gt;
      &lt;%int nc=0; %&gt;
  
          &lt;div id="KMU_alerts"&gt;
              Contact me with alternative notification phone number1.
              &lt;%nc++; %&gt;
                  &lt;form name="kmuform&lt;%=nc%&gt;" id="kmuform&lt;%=nc%&gt;" action="javascript:validatecbr(document.kmuform&lt;%=nc%&gt;,'outage');"&gt;
                      &lt;input type="text" name="cbr1" id="cbr11"
                      onpaste="return false;" style="width: 35px;" maxlength="3"
                      size="2" /&gt;
  
                      &lt;input type="text" name="cbr2" id="cbr22"
                      onpaste="return false;" style="width: 35px;" maxlength="3"
                      size="2" /&gt;
  
                      &lt;input type="text" name="cbr3" id="cbr33"
                      onpaste="return false;" style="width: 35px;" maxlength="4"
                      size="2" /&gt;
  
                      &lt;input id="clickMe" type="button" value="Submit" onclick="javascript:validatecbr(document.kmuform&lt;%=nc%&gt;,'outage');"/&gt;
                  &lt;/form&gt;
          &lt;/div&gt;
  
          &lt;div id="KMU_alerts"&gt;
              Contact me with alternative notification phone number2.
              &lt;%nc++; %&gt;
              &lt;form name="kmuform&lt;%=nc%&gt;"&gt;
                  &lt;input type="text" name="cbr1" id="cbr11"
                  onpaste="return false;" style="width: 35px;" maxlength="3"
                  size="2" /&gt;
  
                  &lt;input type="text" name="cbr2" id="cbr22"
                  onpaste="return false;" style="width: 35px;" maxlength="3"
                  size="2" /&gt;
  
                  &lt;input type="text" name="cbr3" id="cbr33"
                  onpaste="return false;" style="width: 35px;" maxlength="4"
                  size="2" /&gt;
  
                  &lt;input id="clickMe" type="button" value="Submit" onclick="javascript:validatecbr(this.form,'outage');"/&gt;
              &lt;/form&gt;
          &lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>But the code is showing "'cbr11.value' is null or not an object" at "formName.cbr11.value;" this line..</p>
  
  <p>Can someone pls tell me how to pass the form name to a js function and use it to read the form values.</p>