Load Data From Database Via ComboBox and Display in Input Box
Submitted by vandita pandit on Friday, June 14, 2013 - 17:57.
Language
This is a simple application for beginners that loads data from database via combo-box and displays respective data in input box.
Sample code:
- <html>
- <head>
- <script>
- function showgrains(str)
- {
- if (str=="")
- {
- document.getElementById("txtHint").innerHTML="";//txtHint is an event handler
- return;
- }
- 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
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.onreadystatechange=function()//xmlhttprequest object is configured
- {
- if (xmlhttp.readyState==4 && xmlhttp.status==200)//asyncronous request to web server
- {
- document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
- }
- }
- xmlhttp.open("GET","getgrainsinfo.php?q="+str,true);
- xmlhttp.send();
- }
- </script>
- </head>
- <body>
- <form>
- <select name="grains" onChange="showgrains(this.value)">
- <option value="">Select a grain:</option>
- <option value="cotton">cotton</option>
- <option value="cumin">cumin</option>
- <option value="flowers">flowers</option>
- <option value="turmeric">turmeric</option>
- <option value="cashewnut">cashewnut</option>
- </select>
- </form>
- <br>
- <div id="txtHint"><b>grains info will be listed here.</b></div>
- </body>
- </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.
FOR YOUR OWN SAFETY, PLEASE:
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
- 124 views