473,287 Members | 1,418 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

how to retrieve data using dropdown from database using ajax on same page

254 100+
hello i want to display the subjects on the same page based on class selected by user.

i am using dropdown for classes. so when user will select a particular class then it will display subjects in the same page based on class from database.

i am giving my code along with so please tell me the error.

code for database
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include "database.php";
  3. $class1= $_GET['q'];
  4. $selectclass= "SELECT Subjects FROM subjects WHERE Class= '$class1'";
  5. $query=mysql_query($selectclass); 
  6. echo "<table>";
  7. echo"<tr>";
  8. echo"<th> Subjects</th><th>Marks</th></tr>";
  9. while($rows=mysql_fetch_array($query))
  10. {
  11.     echo "<tr>";
  12.     echo "<td>";
  13.     echo $rows['Subjects'];
  14.     echo "</td>";
  15.     echo "<td>";
  16.     echo "<input type= text/>";
  17.     echo "</td>";
  18.     echo "</tr>";
  19.  
  20. }
  21. echo "</table>";
  22. ?>
  23.  
  24.  
code for javascript file
Expand|Select|Wrap|Line Numbers
  1. var xmlHttp;
  2. function selectClass(str)
  3. {
  4.     alert(str);
  5.     xmlHttp=GetXmlHttpObject()
  6.     if(xmlHttp==null)
  7.     {
  8.         alert("Error");
  9.         return 
  10.     }
  11.     var url="getsubject.php";
  12.     url=url+"?q"=str;
  13.     //url=url+"&sid="+Math.random();
  14.     xmlHttp.onreadystatechange=stateChanged
  15.     xmlHttp.open("GET",url,true)
  16.     xmlHttp.send(null)
  17. }
  18.  
  19. function stateChanged() 
  20.     { 
  21.         if (xmlHttp.readyState==4|| xmlHttp.readyState=="complete")
  22.         { 
  23.         document.getElementById("txtselect").innerHTML=xmlHttp.responseText;
  24.         }
  25.     }
  26.  
  27. function GetXmlHttpObject()
  28. {
  29.     var xmlHttp=null;
  30.     try
  31.       {
  32.       xmlHttp=new XMLHttpRequest();
  33.       }
  34.     catch (e)
  35.       {
  36.       try
  37.         {
  38.         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  39.         }
  40.       catch (e)
  41.         {
  42.         xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  43.         }
  44.       }
  45.     return xmlHttp
  46. }
  47.  
i have called javascript file in the header section. i have also used <div element with id txtselect>

but value is not coming and not showing any error as well..I think the value for $class1 is not coming that's why it is showing nothing.

please help me out.
Nov 5 '07 #1
2 5324
Atli
5,058 Expert 4TB
Hi. Welcome to TSDN!

What does the alert(str) show you?
Have you made sure the PHP script works and prints out the expected results? (By navigating to it in your browser)
Nov 10 '07 #2
ak1dnar
1,584 Expert 1GB
http://yourdomain/getsubject.php?q=set_the_value_here
First, execute the server page directly like this. Then you can find where the issue is.
Nov 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Wysiwyg | last post by:
I was hoping to get some opinions on the efficiency of various methods of reusing the same dropdown list data. Here is the situation: Multiple panels on maintenance pages with TAB menus across...
5
by: ggk517 | last post by:
We are trying to develop an Engineering application using PHP, Javascript with Informix as the back-end. Is it possible to retrieve data using Javascript but by accessing the Database. Say...
2
by: Micela | last post by:
Hi, Please help me out in this task. I have a filed in the database of datetime. and 3 dropdown lists in the page. Im using Asp.net with VB coding. The three dropdown lists are 1.for date...
6
by: Daz | last post by:
Hi everyone. Firstly, I apologise if this i not what you would call a PHP problem. I get quite confused as to what lives in which realm, so if this shouldn't be posted here, please suggest where...
1
by: AndiSmith | last post by:
Hi guys, I wondered if anyone could help me with this problem, or even shed some light on the direction I need to take to resolve it? I'm using .NET 2.0 (C# flavor) to build a large user-based...
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
1
by: krishemanth | last post by:
sir, I want to update a value in dropdown using ajax i had a listing of some categories in dropdown along with that i had an add category in that dropdown box when select that addcategory option...
11
by: tokcy | last post by:
Hi everyone, I am new in php and ajax, i am facing the prob while i click on element of first drop down then in second dropdown all element showl come from database. I mean i have three dropdown 1....
1
by: d0353101 | last post by:
Hi, I am having 2 dropdowns on my page. The values in both the drop downs have to be populated through DataBase. Problem : I dont know how to populate the second Dropdown automatically if...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.