My list is generated via php:
<input name="txt_name" list="emp_names" autocomplete="off" id="txt_name" class="textbox" onchange="getID(emp_names.text);"/>
<datalist id="emp_names">
<?php
$host = "localhost";
$user = "root";
$pass = "mark";
$db = "payrolldb";
$cons = mysql_connect($host,$user,$pass);
mysql_select_db($db,$cons);
//query start
$query = "SELECT ID_Employee, CONCAT(LastName,', ',FirstName) AS Name, Department FROM tbl_employeeInfo;";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result))
{
echo "<option value='".$row['Name']."'>".$row['ID_Employee']."</option>
";
}
?>
</datalist>
And it shows up like this.
Each of the options has a text value, which is "15" from the image. the value of the option itself is "Mehta, Jack"
I wanted to know how to get the text value and to pass it from a javascript function.
I tried using an onchange method in both the input and the datalist tag.
But it says Cannot ready property text of 'undefined'.