473,804 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic List Not Working

133 New Member
Hi,

I have a dynamic country and region list i am trying to get working but for some reason when i select a country the next region field does not populate.

Here is the code:

HTML
Expand|Select|Wrap|Line Numbers
  1. <select name="country" onchange="update(this.value)">                        <option value="184">USA</option>
  2.                                                 <option value="183">United Kingdom</option>
  3.                 </select>
  4.  
  5.                 <select name="region" onchange="alert(this.value)">
  6.                     <option value="">Make a selection </option>
  7.                 </select>
  8.  
  9.  

Javascript
Expand|Select|Wrap|Line Numbers
  1.  
  2.     var AdminResponse = "";
  3.  
  4.     function parseResponse(){
  5.  
  6.         var nText = AdminResponse.getElementsByTagName('optionText');
  7.         var nVal = AdminResponse.getElementsByTagName('optionVal');
  8.         document.forms[0]['region'].options.length = 1;
  9.         for (i=0; i<nText.length; i++)
  10.             { 
  11.              var nOption = document.createElement('option'); 
  12.              var isText = document.createTextNode(nText[i].firstChild.data); 
  13.              nOption.setAttribute('value',nVal[i].firstChild.data); 
  14.              nOption.appendChild(isText); 
  15.              document.forms[0]['region'].appendChild(nOption); 
  16.             }
  17.     }
  18.  
  19.     function update(nVal){
  20.  
  21.         var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();   
  22.         AdminRequest.onreadystatechange = function()
  23.             {
  24.               if (AdminRequest.readyState == 4)
  25.                 {
  26.                    if (AdminRequest.status == 200)
  27.                     {
  28.                        AdminResponse = AdminRequest.responseXML;
  29.                        parseResponse();
  30.                     }
  31.                    else     {
  32.                       alert('Error Update.php File '+ AdminRequest.statusText);
  33.                     }
  34.                 }
  35.             }
  36.         var infoStr = "?choice="+nVal;
  37.         AdminRequest.open("GET", "Update.php"+infoStr, true);
  38.         AdminRequest.send(null); 
  39.     }
  40.  
  41.  

PHP
[PHP]
<?php

$choice = $_GET['choice'];
$xml = "<?xml version='1.0' ?><options>";

require_once('i nit.php');

$query = "SELECT * FROM regions WHERE countryid = '$choice'";
$result = @mysql_query($q uery);
$num = @mysql_num_rows ($result);
if ($result && $num > 0)
{
while ($row = mysql_fetch_arr ay($result,MYSQ L_ASSOC))
{
$xml .= "<optionTex t>" . $row['region'] . "</optionText><opt ionVal>" . $row['region'] . "</optionVal>";
}
}
$xml .= "</options>";
@mysql_free_res ult($result);
@mysql_close();
header("Content-Type: text/xml");
echo $xml;

?>
[/PHP]


SQL Structure

id / countryid / region

1 / 184 / Brighton
2 / 184 / Berkshire
3/ 184 / Bath Avon
4 / 184 / Bedfordshire
5 / 183 / Alabama
6 / 183 / Alaska
7 / 183 / American Samoa
8 / 183 / Arizona


Any help would be greatfully appreciated.

Cheers,
Adam
Jan 31 '08 #1
13 1336
acoder
16,027 Recognized Expert Moderator MVP
Hi Adam, welcome to TSDN!

Check the responseXML object. Does it have the data you expect?
Jan 31 '08 #2
adamjblakey
133 New Member
Thank you.

How would i go about checking this?
Jan 31 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
Try alerting it.
Jan 31 '08 #4
adamjblakey
133 New Member
I have just ran Firebug on the page when i select a country and it shows me the following error:

document.forms[0].region has no properties
[Break on this error] document.forms[0]['region'].options.length = 1;

Any Ideas?
Cheers,
Adam
Jan 31 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
That should be document.forms[0].elements['region'].options.
Jan 31 '08 #6
adamjblakey
133 New Member
Hi,

Now i am getting the following error:

document.forms[0].elements.regio n has no properties
[Break on this error] document.forms[0].elements['region'].options.length = 1;

Cheers,
Adam
Jan 31 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
Is this the only or first form on the page?
Jan 31 '08 #8
adamjblakey
133 New Member
Yes there is 2 other forms on the page. I have just removed these and it works fine.

How can i get this to work with the other forms?
Jan 31 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
Instead of forms[0], use forms[formName] to target the particular form.
Jan 31 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
17685
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to Create a Dynamic Crosstab Report PRODUCT :Microsoft Access PROD/VER:1.00 1.10 OPER/SYS:WINDOWS
3
2069
by: Amp Inthalangsy | last post by:
Hi there, Was hoping someone would have an fix for me or some kind or work around. I was able to get my client side dynamic dependent list box working but if my child list data has double quotes or hard breaks as values it wont work at all and I am getting a "underterminated string constant" error. If anyone can help please email me at: ainthalangsy@pembinatrails.ca thanks in andvance
7
3394
by: serge | last post by:
How can I run a single SP by asking multiple sales question either by using the logical operator AND for all the questions; or using the logical operator OR for all the questions. So it's always either AND or OR but never mixed together. We can use Northwind database for my question, it is very similar to the structure of the problem on the database I am working on. IF(SELECT OBJECT_ID('REPORT')) IS NOT NULL DROP TABLE REPORT_SELECTION
1
1511
by: npverni | last post by:
I have a fairly complex form that needs to load and maintain the state of several different dynamic user controls. Here is the workflow: 1) A series of editable user controls (each containing basic web form elements: textboxs, buttons, etc) are loaded from an xml file. 2) The user can either edit these user controls or select from a list of user controls to add to teh page. 3) The user clicks "save" to save the content of all of...
4
18831
by: phcmi | last post by:
I have a PropertyGrid question. My task is to replace a legacy dialog box presentation with a modern one. The dialog itself allows the user to set configuration settings in our application, so it seems to me that a PropertyGrid is a perfect modern replacement. I won't bore you with the details with all the controls on the dialog since I'm only concerned with one issue. The legacy dialog contains a drop down list control that is...
0
1423
by: mtsylvester | last post by:
Hi All, How do I add a List Box to a dynamic Details View. I want to replace the check boxes with list boxes. If I try to simply replace the check box with a list box it complains about not being able to convert it to a datacontrol field. Below is a portion of my current code behind. By the way I tried doing dynamic templates and was not able to get it to work. Please help, this is driving me nuts. Thanks
0
5096
by: mix01 | last post by:
Hi, I am trying to get some VBA code working, but am preplex as to why it does not work. I would really appreciate any level of help. Many thanks, Mix01 Version of the program
1
4665
by: MaryamSh | last post by:
Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
3504
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove) By pressing Add button ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by...
20
6556
by: sirsnorklingtayo | last post by:
hi guys please help about Linked List, I'm having trouble freeing the allocated memory of a single linked list node with a dynamic char* fields, it doesn't freed up if I use the FREE() function in C.. But if I try to use a single linked list with a static char array fields I can free the memory allocated with out any problems using the FREE(). So, why freeing a single linked list with dynamic char* is hard and why the FREE() function is...
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10603
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10099
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9176
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6869
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4314
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.