Как подсказал @diyoda, вставил тег ввода в ячейки для получения данных из основной программы.
//Inserting input tag inside table, to retrieve value from each row in main praogram(only for itmcode and qty)
cell1.innerHTML = count;//SL.NO
cell2.innerHTML = "<input type='text' name='itemCodeRow__" + count + "' value='" + selected_itmcode + "'readonly>";
cell3.innerHTML = sel.options[sel.selectedIndex].text;
cell4.innerHTML = "<input type='text' name='itemQtyRow__" + count + "' value='" + selected_qty + "'readonly>";
Ниже добавлен полный код (может быть полезно, чтобы кто-то узнал всю историю)
{{ define "Smentracker" }}
{{ template "Header" }}
<div id="div-common">
{{ template "Menu" }}
</div>
<form name="form_smen" method="POST" action="smentracker" onsubmit="return ensure_fields()">
<label id="lblDT" class="input-fields" >Date:</label>
<br><input type="date" id="issue_date" name="items_issueDt" class="input-fields" id='datePicker'><br>
<select id="selectSmen" name="selectSmen" class="input-fields">
<option value="0">Select Salesmen </option>
{{ range .Sm_Data }}
<option value="{{ .Id }}">{{ .Desc }} </option>
{{ end }}
</select><br><br>
<p>
<label id="lblDT" class="input-fields" >Add items to list below :</label>
</p>
<select id="selectItem" name="selectItem" class="input-fields">
<option value="0">Select Item </option>
{{ range .Prd_Data }}
<option value="{{ .Id }}">{{ .Desc }} </option>
{{ end }}
</select>
<input type="number" id="qty" placeholder="Enter Quantity">
<button type="button" onclick="addItemtoList()"> Add</button><br><br>
<table id="itemsTable" name="itemtble">
<tr>
<th>SL.No</th>
<th>ItmCode</th>
<th>ItemName</th>
<th>Qty</th>
</tr>
</table>
<br><button type="submit" > Save </button><br>
</form>
</body>
<script>
document.getElementById("issue_date").valueAsDate = new Date()//to Set current date in datepicker
//Add New row in table
function addItemtoList(){
var count = document.getElementById("itemsTable").rows.length;
var table = document.getElementById("itemsTable");
var row = table.insertRow(count);
var cell1 = row.insertCell(0)
var cell2 = row.insertCell(1)
var cell3 = row.insertCell(2)
var cell4 = row.insertCell(3)
//to get the text of selected option ( to get selected item)
var sel = document.getElementById('selectItem');
var selected_item = sel.options[sel.selectedIndex].text;
var selected_qty = document.getElementById('qty').value;
var selected_itmcode = document.getElementById('selectItem').value;
//Inserting input tag inside table, to retrive value from each row in main praogram(only for itmcode and qty)
cell1.innerHTML = count;//SL.NO
cell2.innerHTML = "<input type='text' name='itemCodeRow__" + count + "' value='" + selected_itmcode + "'readonly>";
cell3.innerHTML = sel.options[sel.selectedIndex].text;
cell4.innerHTML = "<input type='text' name='itemQtyRow__" + count + "' value='" + selected_qty + "'readonly>";
function ensure_fields(){
return true;
}
}
</script>
{{ template "Footer" }}
{{ end }}
Ниже приведен фрагмент кода в основной программе для извлечения данных
for{ // picking data and adding to DB till the row ends
iCodeInputName := fmt.Sprintf("%s%d","itemCodeRow__",rowCount)
iQTYInputName := fmt.Sprintf("%s%d","itemQtyRow__",rowCount)
iCode := r.FormValue(iCodeInputName)
iQty := r.FormValue(iQTYInputName)
issueDt := r.FormValue("items_issueDt")
smen_id := r.FormValue("selectSmen")
if iCode == ""{
break
}
insForm, err := db.Prepare("INSERT INTO smen_trans(smen_id,trans_dt,prod_id,qty) VALUES (?,?,?,?)")
if err != nil {
panic(err.Error())
}
insForm.Exec(smen_id,issueDt,iCode,iQty)
rowCount++;
}