Im trying to send a values of "customer ID" to javascript function when I clicked any checkbox of customer's name.
It worked fine for most of the IDs, but some of the ID return a 'weird number' and im sure that's not a number which come from my database(json), more like just a random number.
Pict 1 is the correct output https://i.sstatic.net/u4tIc.png
Pict 2 is the wrong output https://i.sstatic.net/PEaIY.png
There's the code of the checkbox that will do passing the variable into the javascript function(checkFunction) :
Checkbox that return "customer ID" to javascript function (checkFunction(check, no))
<tbody>
<?php for($i=0;$i<$length;$i++){ ?>
<tr>
<td scope="row"><input id="<?php echo $i; ?>" type="checkbox"
onclick="checkFunction(<?php echo $json1[$i]['nik'];?>,
<?php echo $i; ?>,
<?php echo $json1[$i]['verify']; ?>)" >
</td>
<td><?php echo trim($json1[$i]['nik']); ?></td>
<td><?php echo $json1[$i]['nama']; ?></td>
</tr>
<?php } ?>
</tbody>
Here's the javascript function that will alert the length of customer ID and the ID (*ps : Please don't mind the if else condition because the ID did show fine with that condition too)
function checkFunction(check,no) {
var checkBox = document.getElementById(no);
var nik = check;
var verify = 1;
if (checkBox.checked == true){
if(nik.toString().length==5){
alert(nik.toString().length + " " + nik + " " + verify);
}
else if(nik.toString().length==6){
alert(nik.toString().length + " " + nik + " " + verify);
}
else if(nik.toString().length==7){
alert(nik.toString().length + " " + nik + " " + verify);
}
}
Even some of the IDs that below the "0144214 DIRHAM" customer worked fine (I mean the error do skipping, and i cant find any different of the customer ID which would cause the error)
Sorry for my bad english and thanks