I am very new to web development and just learning. I have created a websocket server and now I am working on the actual GUI. The webserver must display a table of data that will dynamically change based on the user input.
What I am struggling with right now is how can I call the javascript function inside a html table?
In the final web, the javascript function will perform HTML request and return a number. This number must be then update a certain row and column in the table.
I have made a simplified example using JSFIddle:
https://jsfiddle.net/a42q1zt0/1/
HTML
<html>
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
th,
td {
padding: 5px;
text-align: left;
}
</style>
</head>
<div>
<input type="button" onClick="insertData()" value="Add">
</div>
<div class="custom-select" style="width:200px;">
<select>
<option value="0">Select operation:</option>
<option value="1">operation1</option>
<option value="2">operation2</option>
</select>
</div>
<br>
<table id="t1">
<caption>Operation table</caption>
<thead>
<tr>
<th>Operation code</th>
<th>To Do</th>
<th>Done</th>
<th>Left</th>
</tr>
</thead>
<tbody>
<tr>
<td>operation1</td>
<td>1000</td>
<td>
<script>
get_number_to_pick();
</script>
</td>
<td>13</td>
</tr>
<tr>
<td>operation2</td>
<td>555</td>
<td>
<script>
get_number_to_pick();
</script>
</td>
<td>15</td>
</tr>
</tbody>
</table>
</html>
Javascript:
function get_number_to_pick() {
var number_to_pick = 50;
return number_to_pick;
}
This seems like a simple task but I have not managed to find a working example of something simmilar on the internet. I hope to get some clarification here. Thanks in advance.