•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 361,924 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,673 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1226 | Replies: 4
![]() |
•
•
Join Date: Oct 2007
Location: England
Posts: 30
Reputation:
Rep Power: 1
Solved Threads: 0
Hey,
I'm trying to create a dynamic drop down box where the first drop down box populates the second drop down, but it isn't working. I have two tables;
pricelist with fields,
-id
-groupname
-item
-price
groups with fields,
-id
-groupname
I've got the code and to me it looks as though it completely works, but i think its the fact that two of the fields have the same name, and it's causing problems.
index.php
findcity.php
When i select an option in the first drop down box, it populates the second with all the values in the table, not just the selected ones.
Cheers
I'm trying to create a dynamic drop down box where the first drop down box populates the second drop down, but it isn't working. I have two tables;
pricelist with fields,
-id
-groupname
-item
-price
groups with fields,
-id
-groupname
I've got the code and to me it looks as though it completely works, but i think its the fact that two of the fields have the same name, and it's causing problems.
index.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function getXMLHTTP() { //fuction to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getItem(strURL) {
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('itemdiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
<?
require_once('../sqlconnect/connect.php');
?>
</head>
<body>
<form method="post" action="" name="form1">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="25">Group</td>
<td width="15"><select name="group" onChange="getItem('findcity.php?group='+this.value)">
<option value="">Select Group</option>
<?
//make query
$query ="SELECT * FROM groups";
$result = mysql_query($query);
//run
$query = mysql_query('SELECT * FROM groups');
if(mysql_error())
{
print(mysql_error());
}
while($row = mysql_fetch_array($query))
{
echo '<option value="'.$row["groupname"].' ">'.$row["groupname"];
}
?>
</select></td>
</tr>
<tr style="">
<td>Item</td>
<td ><div id="itemdiv"><select name="item">
<option>Select Item</option>
</select></div></td>
findcity.php
<select name="item">
<option value="">Select Item</option>
<?
//if so, connect to database
require_once('../sqlconnect/connect.php');
$query="SELECT item FROM pricelist WHERE groupname=$groupname";
$result=mysql_query($query);
$query = mysql_query('SELECT * FROM pricelist');
if(mysql_error())
{
print(mysql_error());
}
while($row = mysql_fetch_array($query))
{
echo '<option value="'.$row["item"].' ">'.$row["item"];
}
?>
</select>When i select an option in the first drop down box, it populates the second with all the values in the table, not just the selected ones.
Cheers
•
•
Join Date: Apr 2005
Location: New York state
Posts: 438
Reputation:
Rep Power: 5
Solved Threads: 62
Well for both files you aren't ending your option tag when you generate them, it may not be what's causing the problem but it's incorrect nonetheless
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
•
•
Join Date: Apr 2005
Location: New York state
Posts: 438
Reputation:
Rep Power: 5
Solved Threads: 62
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Populating Multiple Text Fields Based On A Dynamic Drop-Down List Selection (PHP)
- Help...i think it is simple....Im Just new (PHP)
- Select Box populates text field (JavaScript / DHTML / AJAX)
- Help w/ dynamic list funtction definitions (C++)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: debugging?
- Next Thread: Forms with AJAX


Linear Mode