PHP:
$ports = $Db->query('SELECT port FROM servers');
Javascript:
$("#port").on('keyup', function(){
var port = $("#port").val();
var portlist = <?php print(json_encode($ports)); ?>;
if(jQuery.inArray(port, portlist[port])!==-1)
{
$("#result").removeClass("label-success");
$("#result").removeClass("label-warning");
$("#result").addClass("label label-danger");
$("#result").html("Port belegt!");
}
else
{
$("#result").removeClass("label-danger");
$("#result").removeClass("label-warning");
$("#result").addClass("label label-success");
$("#result").html("Port Frei!");
}
})
Why is this not working?
The array contains 1234 and 7777.
So if I type 7777 into the html input field (#port) it should do the first action (if true)
But it always goes into the else action.
if(jQuery.inArray(port, portlist[port])!==-1)toif(jQuery.inArray(port, portlist)!==-1). Otherwise you'd need to check if portlist[port] exists and that's not inArray.[object Object]