Populating an input field from selected data on a dropdown list

I am trying to design a form using Ajax, mysql and PHP. I want a situation where by the selected item will output a particular field on the database and displayed as value in a form input field. right now, I do not know how to insert value into the input field of the form.
Here are my codes:

function showunit(str) {

if (str == “”) {

enter code here
document.getElementById(“displayunit”).innerHTML = “”;


} else {

if (window.XMLHttpRequest) {

// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {

// code for IE6, IE5
xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById(“displayunit”).innerHTML = xmlhttp.responseText;

S/N Select drug —

fetch_assoc()){ ?>


Source: php

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.