SunQuest
 
           JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript 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:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old June 16th, 2004, 02:52 PM
Scot Scot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 29 Scot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 17 sec
Reputation Power: 0
Syncronizing two select boxes to work together

I am trying to syncronize two select boxes so that they are connected. For example when a user selects a name from select box 1 select box 2 displays the id number associated with that name in my table. The code for the two select boxes is as follows. I have each one pulling the data from the appropriate field in the database. I just can't figure out how to connect them so that a selection in the first automatically causes the related item to appear in select box two. Any and all suggestions are appreciated. I thought I saw a similar post here but was unable to find it. Thanks Have an Awesome Day!

<!doctype html public "-//W3C//DTD HTML 4.0 //EN">
<html>
<head>
<title>Title here!</title>
</head>
<body>
<?php

include ('global.php');
?>

//////////////////Select box 1
<select name='CLNAME'>
<?PHP

$result = mysql_fetch_array(mysql_query("SELECT CLNAME FROM _clientsw_cases WHERE CLIENTNUM = '$CLIENTNUM'"));
$user_val = $result['CLNAME'];

$query = mysql_query("SELECT * FROM _clientsw_cases");
while($array = mysql_fetch_array($query)) {
if($array['CLIENTNUM'] == $user_val) {
print "<option selected value=$array[CLIENTNUM]>$array[CLNAME]</option>";
} else {
print "<option value=$array[CLIENTNUM]>$array[CLNAME]</option>";
}
}
?>
</select>


////////////////////Select box 2
<select name='CLIENTNUM'>
<?PHP

$result = mysql_fetch_array(mysql_query("SELECT CLIENTNUM FROM _clientsw_cases WHERE CLIENTNUM = '$CLIENTNUM'"));
$user_val = $result['CLIENTNUM'];

$query = mysql_query("SELECT * FROM _clientsw_cases");
while($array = mysql_fetch_array($query)) {
if($array['CLIENTNUM'] == $user_val) {
print "<option selected value=$array[CLIENTNUM]>$array[CLIENTNUM]</option>";
} else {
print "<option value=$array[CLIENTNUM]>$array[CLIENTNUM]</option>";
}
}
?>
</select>
</body>
</html>

Reply With Quote
  #2  
Old June 16th, 2004, 05:48 PM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 5
I'm sure this wouldn't be too hard to set up but its a javascript problem not a php one and my javascript is a bit rusty. If the values are entered into the two select boxes in the same order then you can grab the index of the first when its changed and set the second one to that index. How you'd do that though I don't know, sorry.

-KM-

Reply With Quote
  #3  
Old June 17th, 2004, 07:07 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Moved this over to the js forum. I'm not sure why you'd want to have two select boxes for this. Typically, when you're wanting interacting select boxes, it's when you've got multiple possible values associated with single parent selectors (categories and subcategories, for example). In any case, you can do this pretty easily with js. A very good, lightweight, easy script for this can be found at http://javascript.geniusbug.com/ind...howScript&id=30. You just have to set your PHP up so that it prints out the appropriate js statements and the script takes care of the rest.
__________________
Please don't PM me asking for solutions outside the scope of a thread.
Keeping all responses in a thread stands to help others who come along later,
which is after all what this forum's all about.

Reply With Quote
  #4  
Old June 17th, 2004, 07:36 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
lol - this gets asked almost weekly - http://www.mattkruse.com - javascripts section, under Dynamic Option List
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
  #5  
Old June 17th, 2004, 08:39 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
You know, I looked at Matt's script when I had a need for this the other day and found it long and a pain to configure compared to the one I've referenced, which is something like about a fifth the length and works just as well (for two select boxes, at least -- I didn't try more than that). At any rate, these are two of many such scripts available.

Reply With Quote
  #6  
Old June 17th, 2004, 08:43 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
Kewl - thanks for the tip D.
Last time I used dynamic option lists, I've found they have problems when hitting "back" after submitting, and they're also difficult to load correctly selected from some saved DB settings, for example - i.e. they're a lot of work!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Syncronizing two select boxes to work together


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 1 hosted by Hostway