Load Data From Database Via ComboBox and Display in Input Box

Submitted by: 
Visitors have accessed this post 7044 times.

This is a simple application for beginners that loads data from database via combo-box and displays respective data in input box.

Sample code:

  1. <html>
  2. <head>
  3. <script>
  4. function showgrains(str)
  5. {
  6. if (str=="")
  7. {
  8. document.getElementById("txtHint").innerHTML="";//txtHint is an event handler
  9. return;
  10. }
  11. if (window.XMLHttpRequest) //XMLHttp request object is created and we are checking whether ajax works in diffrent browsers..i.e we are checking browser compatibity
  12. {// code for IE7+, Firefox, Chrome, Opera, Safari
  13. xmlhttp=new XMLHttpRequest();
  14. }
  15. else
  16. {// code for IE6, IE5
  17. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  18. }
  19. xmlhttp.onreadystatechange=function()//xmlhttprequest object is configured
  20. {
  21. if (xmlhttp.readyState==4 && xmlhttp.status==200)//asyncronous request to web server
  22. {
  23. document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  24. }
  25. }
  26. xmlhttp.open("GET","getgrainsinfo.php?q="+str,true);
  27. xmlhttp.send();
  28. }
  29. </script>
  30. </head>
  31. <body>
  33. <form>
  34. <select name="grains" onChange="showgrains(this.value)">
  35. <option value="">Select a grain:</option>
  36. <option value="cotton">cotton</option>
  37. <option value="cumin">cumin</option>
  38. <option value="flowers">flowers</option>
  39. <option value="turmeric">turmeric</option>
  40. <option value="cashewnut">cashewnut</option>
  41. </select>
  42. </form>
  43. <br>
  44. <div id="txtHint"><b>grains info will be listed here.</b></div>
  47. </body>
  48. </html>

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.