MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 15th, 2004, 10:39 PM
franches franches is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 16 franches User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question drop down and textbox

I have encountered this code here. This code shows 2 drop down or combo box in page.php, one for Project and the other for Activity. The data of grupper and varer will be retrieved from mysql. The drop down for Activity depends on the value selected on Project drop down. Thus, I also want to add a textbox(ProjectCode) after the 1st drop down (Project) another textbox(ActivityCode) after the second drop down(Activity). The textbox(ProjectCode) depends on the value selected on dropdown(Project) and the textbox(ActivityCode) depends on the value selected on dropdown(Activity). I really need help with the code. I have highlighted in blue the field that holds the ProjectCode and ActivityCode.

Thank you.


PHP Code:
<html
<
body>
 
<?
php
mysql_connect
("localhost""root")
or die( 
"Unable to connect\n"mysql_error() ); 
 
mysql_select_db("test"
or die(
"Unable to select db ".mysql_error()."\n");
 
$id = [QUOTE]%4$s[/QUOTEGET['id'];
 
echo
'<form name="testform">';
$q mysql_query("SELECT * FROM grupper");
echo
"<select name=\"gruppe\" onChange=\"Load_id()\">";
while(
$row mysql_fetch_array($q)) {
$selected = ($row["gruppe_id"] == $id)? "SELECTED":"";
echo
"<option value=\"".$row['gruppe_id']."\""$selected." >".$row['gruppe_navn']."</option>";
}
echo
"</select>";
 
 
$q2 mysql_query("SELECT * FROM varer WHERE vare_gruppe_id = $id");
echo
"<select name=\"vare\">";
while(
$row mysql_fetch_array($q2)) {
echo
"<option value=\"".$row['vare_id']."\">".$row['vare_navn']."</option>";
}
echo
"</select></form>";
?>
 
<script type="text/javascript">
function Load_id() 
{
var id = document.testform.gruppe.options[document.testform.gruppe.selectedIndex].value
var id_txt = "?id="
location = id_txt + id
}
</script>
</BODY>
</HTML> 



Quote:
DB_DUMPS////////////////////////////

CREATE TABLE `grupper` (
`gruppe_id` int(11) NOT NULL auto_increment,
`gruppe_navn` varchar(60) NOT NULL default '',
`gruppe_code` varchar(60) NOT NULL default '',
PRIMARY KEY (`gruppe_id`)
) TYPE=MyISAM AUTO_INCREMENT=3 ;

INSERT INTO `grupper` VALUES (1, 'testgruppe1','P120');
INSERT INTO `grupper` VALUES (2, 'testgruppe2','P110');


CREATE TABLE `varer` (
`vare_id` int(11) NOT NULL auto_increment,
`vare_gruppe_id` int(11) NOT NULL default '0',
`vare_navn` varchar(60) NOT NULL default '',
`vare_code` varchar(60) NOT NULL default '',
PRIMARY KEY (`vare_id`)
) TYPE=MyISAM AUTO_INCREMENT=5 ;

INSERT INTO `varer` VALUES (1, 1, 'testvare1','A123');
INSERT INTO `varer` VALUES (2, 1, 'testvare2','A345');
INSERT INTO `varer` VALUES (3, 2, 'testvare3','A456');
INSERT INTO `varer` VALUES (4, 2, 'testvare4','A789');

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > drop down and textbox


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway