[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.4

Howto Change values in one dropdown, based on the result of another dropdown

Asked by Gerhard in JavaScript

Tags: javascript, array, mysql_query, value

This Javascript question but it is combined with the use of PHP. The PHP code is purely for database access and is not what I'm worried about in this question.

I have a table created with the following structure...

CREATE TABLE regions (
   location varchar(50),
   country varchar(20),
   province varchar(20),
   region varchar(20)
);

I would like to have a form with 4 dropdown boxes:
1) Country
2) Province
3) Region
4) Location

I would further like to dynamically update these boxes in the following way:

If a country is selected then the provinces for that country is loaded in the province box.

If a province is selected then the regions for that province is loaded in the regions box

If a region is selected then the location for that region is loaded in the locations box

If managed to make use of Java script code I've found to do just this for the country and the province boxes.

Question is..


How do I do this for all 4 boxes? I will give 250 points for source code that I have to make minimal changes to. I will also supply a SQL dump table to allow you to create the table populated with data if you email me jvrensgg@telkom.co.za

Here is the Java script source code that I got working in my PHP3 file.

<%
//Table: REGIONS
//FIELDS: COUNTRY, REGION, PROVINCE, LOCATION
%>
<html>

<head><script language="JavaScript"><!--
var returnCode = 0;
var errorDesc = "";

var selectArr = new Array();

function sel(value, text) {
this.text = text;
this.value = value;
this.children = new Array();
}

function opt(value, text) {
this.text = text;
this.value = value;
}

function addCountryParent(value, text) {
var newPos = selectArr.length;
selectArr[newPos] = new sel(value, text);
return newPos;
}

function getCountryParentPosition(value) {
for (var i in selectArr) {
if (selectArr[i].value == value) {
return i;
break;
}
}
return -1;
}

function addProvince(parentValue, value, text) {
var parentPos = getCountryParentPosition(parentValue);
if (parentPos == -1) {
returnCode = -1;
errorDesc = "Problem with data, no parent";
} else {
selectArr[parentPos].children[selectArr[parentPos].children.length] = new opt(value, text);
}
}

function drawCountrySelect() {
var selectObj = document.myForm.select1;
if (document.layers) {
selectObj.options.length = 0;
} else {
selectObj.innerHTML = "";
}
for (var i in selectArr) {
selectObj.options[selectObj.options.length] = new Option(selectArr[i].text,selectArr[i].value);
}
selectObj.selectedIndex = 0;
}

function drawProvinceSelect() {
var currentSelect = document.myForm.select1.selectedIndex;
var selectObj = document.myForm.select2;
if (document.layers) {
selectObj.options.length = 0;
} else {
selectObj.innerHTML = "";
}
for (var i in selectArr[currentSelect].children) {
selectObj.options[selectObj.options.length] = new Option(selectArr[currentSelect].children[i].text,selectArr[currentSelect].children[i].value);
}
selectObj.selectedIndex = 0;
}

function init() {
if (returnCode == 0) {
drawCountrySelect();
drawProvinceSelect();
} else {
alert(returnCode+":"+errorDesc);
}
}

<%


      //******************************************************************
      //initialize database info
      //******************************************************************
      require("phpoptions.inc");

      $db = mysql_connect($server,$uid,$pwd);

      mysql_select_db($dbname,$db);

      $result = mysql_query("select distinct province from regions order by province",$db);

      while ($myrow = mysql_fetch_array($result)) {
            echo "addCountryParent(\"$myrow[province]\",\"$myrow[province]\");\n";
   }

      $result = mysql_query("select distinct province, region from regions order by region",$db);

      while ($myrow = mysql_fetch_array($result)) {
            echo "addProvince(\"$myrow[province]\",\"$myrow[region]\",\"$myrow[region]\");\n";
      }
 


%>


// --></script>

<title></title>
</head>

<body onLoad="init()">

<form name="myForm">
  <p><select name="select1" onChange="drawProvinceSelect()" size="1">
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
  </select> </p>
  <p><select name="select2" size="1">
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
    <option> </option>
  </select> </p>
</form>
</body>
</html>
[+][-]08/22/00 08:48 AM, ID: 4026188Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/22/00 08:51 AM, ID: 4026214Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/22/00 05:29 PM, ID: 4030770Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/23/00 08:17 AM, ID: 4038286Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/23/00 09:43 AM, ID: 4039587Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/23/00 11:36 AM, ID: 4041466Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/00 01:30 AM, ID: 4094056Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/28/00 10:45 AM, ID: 4101250Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/28/00 10:00 PM, ID: 4108391Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08/29/00 01:21 AM, ID: 4109833Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08/29/00 10:52 AM, ID: 4118350Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: JavaScript
Tags: javascript, array, mysql_query, value
Sign Up Now!
Solution Provided By: kg_bang
Participating Experts: 3
Solution Grade: A
 
[+][-]08/30/00 04:43 AM, ID: 4127576Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]08/30/00 04:43 AM, ID: 4127577Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09/01/00 07:49 AM, ID: 4157422Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/30/01 10:33 AM, ID: 199593Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/30/01 10:54 AM, ID: 199671Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/30/01 02:25 PM, ID: 200307Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/30/01 03:23 PM, ID: 200438Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/30/01 04:22 PM, ID: 200562Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/30/01 04:56 PM, ID: 200654Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/31/01 07:12 AM, ID: 203181Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/31/01 08:09 AM, ID: 203471Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81