Ajax Php Mssql ~ One drop down menu populate another! Help.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
vip2k
Forum Newbie
Posts: 3
Joined: Tue May 08, 2007 8:38 am

Ajax Php Mssql ~ One drop down menu populate another! Help.

Post by vip2k »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi everyone,

i want to populate the "component drop down menu" from the "project drop down menu".. but i don't know how to write the AJAX code for it?
can anyone help?

my goal is to find out values for $selectedProject and $selectedComponent

Thanks a lot

Code: Select all

<form name="myform" class="config" id="config" action="" method="POST">
	<b>Configure DevTrack Module:</b><br />

		Project:<select name="project">
		<?php
			$devtrackDB = new DBControllerDevTrack();

			$res = $devtrackDB->quick_query("SELECT ProjectName from Project");

			echo '<option value="">Select a Project</option>';

			while($data = mssql_fetch_assoc($res))
			{
				$projectName = $data['ProjectName'];

				echo '<option value="'.$projectName.'">'.$projectName.'</option>';
			}
			$selectedProject = "how to get this value?";
		?>
		</select><br />

		Component:<select name="components">
		<?php
			$res = $devtrackDB->quick_query("SELECT ProjectID from Project WHERE ProjectName='".$selectedProject."'");

			$id = mssql_fetch_assoc($res);

			$res2 = $devtrackDB->quick_query("SELECT BugTypeName from BugTypes WHERE ProjectID='".$id['ProjectID']."'");

			echo '<option value="">Select a Component</option>';

			while($data = mssql_fetch_assoc($res2))
			{
				$bugTypeName = $data['BugTypeName'];

				echo '<option value="'.$bugTypeName.'">'.$bugTypeName.'</option>';
			}
			$selectedComponent = "how to get this value?";
		?>
		</select><br />

		<input type="submit" value="Submit" />
		<input type="reset" value="Reset" />
	</form>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
arturm
Forum Commoner
Posts: 86
Joined: Fri Apr 13, 2007 8:29 am
Location: NY
Contact:

Post by arturm »

For the beginners with AJAX I would suggest to use prototype js framework http://www.prototypejs.org/

It is very simple to send and receive requests from the server.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

This is not a PHP issue, but a Javascript issue. This post is being moved.

Before you get into the AJAX side of this, trying searching for 'populate select box when selection made' in Javascript. There a number of tutorials available for this, and it doesn't necessarily need AJAX (it makes it cooler, but it is not required).
Post Reply