Jump to content

Ajax DropDown Menus


adamjblakey

Recommended Posts

Hi,

 

I have this function here:

 

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); 
}

 

What this does is when i select a region from a list it dynamically fills the town list with the relevant towns.

 

My problem is that i have 3 fields for regions and 3 towns so i need to replicate this function 3 times but don't know which bits to change.

 

Please can someone help me out.

 

Adam

Link to comment
https://forums.phpfreaks.com/topic/99935-ajax-dropdown-menus/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.