title: HTML Form Submission in golang template
body: <p>I am using the go language to submit an HTML form using the go-template. Getting some weird results.</p>
  
  <p>The basic idea is that I have a data structure called Page containing a few elements. The template is populated with an array of Pages. Inside the template I iterate through each Page and display its contents. Each of these contents are embedded inside an HTML form with its respective link. Once the link is clicked it will submit the respective form.</p>
  
  <p>The code snippet is as follows:</p>
  
  <pre><code>{{range $index, $element := .Pages}}                                                                            
    &lt;form action="/detailNews" id="readMore{{$index}}" method="post" name="readMore{{$index}}"&gt;
      //displaying elements from each page                    
  
      &lt;div id="more"&gt;
        &lt;input name="query" type="hidden" value="{{printf "%s" .Title}}"&gt;                         
        &lt;a href="#" onclick="document.readMore{{$index}}.submit()"&gt;Read More&lt;/a&gt;
      &lt;/div&gt;
  
    &lt;/form&gt;
  {{end}}
  </code></pre>
  
  <p>The code mostly works with one little problem. The id and the name attributes generate outputs as expected such as: <strong>readMore0</strong>, <strong>readMore1</strong>, etc.</p>
  
  <p>The problem is at the "a" tag where the onclick attribute is populated with this: <strong>document.readMore 0 .submit()</strong>, <strong>document.readMore 1 .submit()</strong>, etc. Note the <strong>space</strong> surrounding 0, 1. With this, the respective form is not being found when the link is clicked.</p>
  
  <p>I can't figure out the reason of this.</p>
  
  <p>Any help will be highly appreciated.</p>
  
  <p>Thanks,
  Ripul</p>