I am using the go language to submit an HTML form using the go-template. Getting some weird results.
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.
The code snippet is as follows:
{{range $index, $element := .Pages}}
<form action="/detailNews" id="readMore{{$index}}" method="post" name="readMore{{$index}}">
//displaying elements from each page
<div id="more">
<input name="query" type="hidden" value="{{printf "%s" .Title}}">
<a href="#" onclick="document.readMore{{$index}}.submit()">Read More</a>
</div>
</form>
{{end}}
The code mostly works with one little problem. The id and the name attributes generate outputs as expected such as: readMore0, readMore1, etc.
The problem is at the "a" tag where the onclick attribute is populated with this: document.readMore 0 .submit(), document.readMore 1 .submit(), etc. Note the space surrounding 0, 1. With this, the respective form is not being found when the link is clicked.
I can't figure out the reason of this.
Any help will be highly appreciated.
Thanks, Ripul