I am Populating values in textbox based on listbox changed
My code is working ...and also getting data properly...
BUT This works on the basis of id.
I need to select data based on cityname.
below is my code
<?php
require_once('includes/config.php');
?>
<?php
$result1 = $database->getRows("SELECT * from areamaster");
?>
<html>
<head>
<script type="text/javascript">
    var compInfoArray = [
        <?php                       
           foreach($result1 as $row1){ 
                echo 'id : ' . $row1['id'] . ',';
                echo 'cityname :  "'.$row1['cityname'].'",';
                echo 'area : "'.$row1['area'].'"';
            }
        ?>
    ];
    function showname() {
  var id = document.form1.id.value;
  var index = compInfoArray.contains(id);
  document.form1.cityname.value = compInfoArray[index]["cityname"];
  document.form1.area.value = compInfoArray[index]["area"];
}
window.onload = function() {
  showname();
}
Array.prototype.contains = function(needle) {
  for (var i in this) {
    for (var key in this[i]) {
      if (this[i][key] == needle) {
        return i;
      }
    }
  }
  return false;
}
</script>
  </head>
</head>
<body>
<form name="form1">
  <select name="id" onChange="showname()">
<?php foreach($result1 as $row1){   ?>  
    <option  value="<?php echo $row1["cityname"]; ?>"><?php echo $row1["cityname"]; ?></option>
    <?php }?>       
  </select>
  <label>
    <input type="text" name="cityname" value="" />
    <input type="text" name="area" value="" />
  </label>
</form>
</body>
    </html>
 
    