Hi,
I am using the following function to do a country/region ajax drop down list. -
// JavaScript Document
-
-
var AdminResponse = "";
-
-
function parseResponse(){
-
-
var nText = AdminResponse.getElementsByTagName('optionText');
-
var nVal = AdminResponse.getElementsByTagName('optionVal');
-
document.forms[0]['region'].options.length = 1;
-
for (i=0; i<nText.length; i++)
-
{
-
var nOption = document.createElement('option');
-
var isText = document.createTextNode(nText[i].firstChild.data);
-
nOption.setAttribute('value',nVal[i].firstChild.data);
-
nOption.appendChild(isText);
-
document.forms[0]['region'].appendChild(nOption);
-
}
-
}
-
-
function update(nVal){
-
-
var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
-
AdminRequest.onreadystatechange = function()
-
{
-
if (AdminRequest.readyState == 4)
-
{
-
if (AdminRequest.status == 200)
-
{
-
AdminResponse = AdminRequest.responseXML;
-
parseResponse();
-
}
-
else {
-
alert('Error Update.php File '+ AdminRequest.statusText);
-
}
-
}
-
}
-
var infoStr = "?choice="+nVal;
-
AdminRequest.open("GET", "Update.php"+infoStr, true);
-
AdminRequest.send(null);
-
}
-
This will bring a list of regions based on what country is selected, what i need though is when a region is selected another list is generated with towns.
So basically i need the above duplicating but don't know which bits need changing.
Thanks in advanced for the help.
Cheers,
Adam
Mar 20 '08
13 1438
As an example, - function parseResponse(field){
-
-
var nText = AdminResponse.getElementsByTagName('optionText');
-
var nVal = AdminResponse.getElementsByTagName('optionVal');
-
document.forms[0][field].options.length = 1;
-
for (i=0; i<nText.length; i++)
-
{
-
var nOption = document.createElement('option');
-
var isText = document.createTextNode(nText[i].firstChild.data);
-
nOption.setAttribute('value',nVal[i].firstChild.data);
-
nOption.appendChild(isText);
-
document.forms[0][field].appendChild(nOption);
-
}
-
}
-
-
function update(nVal, field){
-
-
var AdminRequest = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
-
AdminRequest.onreadystatechange = function()
-
{
-
if (AdminRequest.readyState == 4)
-
{
-
if (AdminRequest.status == 200)
-
{
-
AdminResponse = AdminRequest.responseXML;
-
parseResponse(field);
-
}
-
else {
-
alert('Error Update.php File '+ AdminRequest.statusText);
-
}
-
}
-
}
-
var infoStr = "?choice="+nVal;
-
AdminRequest.open("GET", "Update.php"+infoStr, true);
-
AdminRequest.send(null);
-
}
See how I've added field to update(). This is the name of the field. In parseResponse() , I've replaced "region" with field, so you just need to pass the name of the element when you call update().
Thanks for that, it makes a lot more sense now.
I am still a little confused though. Basically on her you do something like this? onChange="updat e(this.value || field=town)"
I does not work though?
acoder 16,027
Recognized Expert Moderator MVP
No, it should be called like this: - onchange="update(this.value,'town')"
Thanks a million, works a treat :)
acoder 16,027
Recognized Expert Moderator MVP
Righto, glad it's working.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: David Laub |
last post by:
I have stumbled across various Netscape issues, none of which appear to be
solvable by tweaking the clientTarget or targetSchema properties. At this
point, I'm not even interested in "solving" these problems - I'm more
interested in isolating them, .i.e. finding a "complete" list of issues.
Here's my list of serious issues found so far. By serious, I mean
functionality that fails, as opposed to much less serious (albeit annoying)
display...
|
by: DartmanX |
last post by:
Hi,
Looking for recommendations for a decent API for AJAX work. I need it
to be somewhat documented so I can figure out how to actually use it.
My most critical need right now is clean code for a "triple" chained
selector (state->county->city).
Jason
|
by: jay_dev |
last post by:
hi all,
im using ajax to replace a dropdown list through a server side script
in mozilla it works pretty fine
but in IE i get the stupid R0625 error and who knows what it is
i tried to tweak the code but nothing, IE crashes and my whole application fails
im using IE6
help anyone!!
|
by: meltedown |
last post by:
This is supposed ot be an example:
http://www.ajaxtutorial.net/index.php/2006/11/30/simple-ajax-using-prototype-part-2/
It says :
This example is probably the simplest example you will ever find.
We are going to use the prototype feature ‘ajax.Updater’ (see part one
for more details on prototype).
|
by: geevaa |
last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3
XMLHttpRequest and AJAX for PHP programmers
James Kassemi
Introduction:
Although the concept isn't entirely new, XMLHttpRequest technology is
implemented on more sites now than ever. Compatibility is no longer an
issue (IE, Mozilla and Opera all support it), and the benefits to
using it are amazing. There are too many PHP programmers avoiding any
| |
by: schmeckel |
last post by:
I am trying to use some very basic AJAX functionality (update panel
for partial page update) on my website. When I run my webpage in VS
2005, the partial page update works fine. However, when I upload the
page to my website and try running it, the page updates as a full page
update rather than a partial page update. I believe the web.config
I'm using is correct and I have also put the System.Web.Extensions dll
in my BIN folder.
Can...
|
by: UKuser |
last post by:
Hi,
I'm working on the following code, which works fine in Firefox, but
not in IE. The problem is its not posting the variable to my page and
I'm thinking its something wrong with the getElementByID but the code
is as per an example on a tutorial website (http://www.tizag.com/
ajaxTutorial/ajax-javascript.php).
The Select element is as follows:
<select style="width:240px;font-size:8pt" id='servicet'
|
by: rpollard |
last post by:
Hi,
I am relatively new to Ajax and am wondering if someone can shed a bit of light on the conceptual part of how Ajax handles its communication.
Not knowing a whole lot about Ajax when I started coding I copied some code from the Internet that seem to be the accepted way of creating the object and using it.
This is the code I am using on the Javascript side:
------------------------------------------------------------------------
var...
|
by: RichB |
last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am
trying to add a tabbed control to the page.
I have no problems within the aspx file, and can dynamically manipulate a
tabcontainer which has 1 panel already, however I want to try create the
TabPanels dynamically. I followed the advice here:
http://www.asp.net/learn/ajax-videos/video-156.aspx (3rd comment - Joe
Stagner)
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
| | |