our 10 year old software used to be written in PHP, combined with HTML and SQL snippets. I am forced to make the best out of it.
Having no experience at all with JavaScript, I have to use jQuery's inArray to get the index by value.
Although everything seems to be right, inArray returns -1 all the time, although I should get the proper index. So what have I done wrong?
$html1 .= "<script src='/js/jquery-3.2.1.min.js'> </script>
<script> var juseridarray = ".json_encode($useridarray).";
$(document).ready(function()
{
$('#chiefname').change(UpdateInfo);
$('#chiefid').change(UpdateInfo);
$('#chiefs').change(UpdateInfo);
});
function UpdateInfo()
{
var chiefname = $('#chiefname').val();
var chiefid = $.inArray( chiefname, juseridarray);
var chief = chiefid;
$('#chief').val(chief);
console.log(juseridarray);
console.log(chiefname);
}
</script>";
Excuse me, I forgot to mention the log output. So this is a snippet of juseridarray log output which I copied from firebug:
Object[430]
1: "Administrator"
3: "Bob"
8: "Wegner, Meike "
10: "Uhrenbauer, Sonja"
[426 more...]
The array seems to have an correct index and correct values. So when I search for 'Bob', inArray returns -1, although 'Bob' is expected to return 3. On the other hand, I get 'Bob' in return when using
console.log(juseridarray[3]);
The array content is static. It doesn't change in runtime. And if it would, usernames would always keep their id (stored as index)