Title: How to multiply multiple input type number with the same ID and name
Tags: php;jquery;mysql;forms
Question: This code is working fine, but mine has multiple inputs with same ID and name. I think the multiple statements don't recognize another ID.

```while($d = mysqli_fetch_array($data)){
?&gt;
<tr&gt;
<td align="text-center"&gt;<?php echo $no++; ?&gt;</td&gt;
<td align="text-center"&gt;<input type="text" name="naran[]" value="<?php echo $d['naran'];?&gt;"&gt;</td&gt;
<td align="text-center"&gt;<input type="hidden" name="kode_sasan[]" value="<?php echo $d['kode_sasan'];?&gt;"&gt;</td&gt;
<td align="text-center"&gt;<input type="number" name="hamutuk[]" onfocus="sr()" onblur="psr()" id="hamutuk" &gt;</td&gt;
<td align="text-center"&gt;<input type="number" name="total[]" id="total" &gt;</td&gt;
<td align="text-center"&gt;<input type="hidden" value="<?php echo $d['folin_faan'];?&gt;" name="folin_faan[]" onfocus="sr()" onblur="psr()" id="folin_faan""&gt;</td&gt;
<td&gt;<a href="update.php?edit=<?php echo $d['id']; ?&gt;"" type="button" class="btn btn-info glyphicon glyphicon-pencil"&gt;</a&gt;
    <a onclick="return confirm('Ita boot Hakarak Duni atu hamos?')" href="hamosfaan.php?hms=<?php echo $d['kode_sasan']; ?&gt;"  type="button" class="btn btn-danger glyphicon glyphicon-remove"&gt;</a&gt;
  </td&gt;
 </tr&gt;
<?php } ?&gt;
</table&gt;
<button   type="submit" name="sosa" class="btn btn-primary "&gt;Processa</button&gt;
</form&gt;
 <script type="text/javascript"&gt;
function kms(){
Interval = setInterval ("sr()",1);
}
function sr(){
folin_faan=parseFloat(document.getElementById("folin_faan").value);
hamutuk=parseFloat(document.getElementById("hamutuk").value);
total = folin_faan * hamutuk;
 document.getElementById("total").value=total.toFixed(2);
}
function psr(){
clearInterval(Interval);
}
</script&gt;
```

Comment: Any idea of id must be unique. Is anyway to use?

Comment: Multiple inputs with the same id is not valid HTML. id must be unique within the document.

Comment: You can use classes instead. You can add event listeners to the fields that are used to calculate the totals, and find the other relevant inputs in the same row as the input that caused the event.


Here is another answer: do not use the same ID.
you can make your id unique. on your while loop, you can manipulate the ID.

for example

```<td align="text-center"&gt;<input type="number" name="hamutuk[]" onfocus="sr(<?php echo $no;?&gt;)" onblur="psr(<?php echo $no;?&gt;)" id="hamutuk<?php echo $no;?&gt;" &gt;</td&gt;
```

Comment for this answer: how about id for total  to showing results : 

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2019:00:02/15/19', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<php><jquery><mysql><forms>', 'Title': 'How to multiply multiple input type number with the same ID and name', 'ViewCount': 169, 'id': 54700963, 'user_AboutMe': '<p>I am a finished student of one university in East Timor\ni was finished in 2015 and had been worked with one of famous company in East Timor \nis Telemor comunication company </p>\n\n<p>and now i am focus on PHP and Mysql to be Web Developer.</p>\n', 'user_AccountId': 13636451.0, 'user_DisplayName': 'atoy amsal', 'user_Reputation': 11.0, 'user_Views': 9.0, 'user_id': 9837355.0}}