Hi,
I have a function here: -
var AdminResponse = "";
-
-
function parseResponse(){
-
-
var nText = AdminResponse.getElementsByTagName('optionText');
-
var nVal = AdminResponse.getElementsByTagName('optionVal');
-
document.forms["area"].elements['town'].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["area"]['town'].appendChild(nOption);
-
}
-
}
-
This is part of a Ajax drop down menu for region and town, i want to mod this so that it can work on three different fields as i have three selections for region and town.
I thought this would work but it doesn't. - var AdminResponse = "";
-
-
function parseResponse(field){
-
-
var nText = AdminResponse.getElementsByTagName('optionText');
-
var nVal = AdminResponse.getElementsByTagName('optionVal');
-
document.forms["area"].elements['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["area"]['field'].appendChild(nOption);
-
}
-
}
-
-
On the drop down itself i have put: - onchange="update(this.value,'town')"
Any ideas?
14 1565
Change ['field'] to [field]. You want to use the field variable, not the string "field" which probably doesn't exist.
Thank you for your reply,
I have put this now but still does not work. - var AdminResponse = "";
-
-
function parseResponse(field){
-
-
var nText = AdminResponse.getElementsByTagName('optionText');
-
var nVal = AdminResponse.getElementsByTagName('optionVal');
-
document.forms["area"].elements[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["area"][field].appendChild(nOption);
-
}
-
}
I get this error:
document.forms.area.elements[field] has no properties
parseResponse(undefined)ajax.js (line 8)
onreadystatechange()ajax.js (line 30)
[Break on this error] document.forms["area"].elements[field].options.length = 1;
Cheers,
Adam
Are you passing the field name to parseResponse() properly?
What does your update function look like?
Here is the full set of code: -
-
var AdminResponse = "";
-
-
function parseResponse(field){
-
-
var nText = AdminResponse.getElementsByTagName('optionText');
-
var nVal = AdminResponse.getElementsByTagName('optionVal');
-
document.forms["area"].elements[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["area"][field].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);
-
}
-
-
On line 29 of that update method, you seem not to be passing the field.
If this was the case would it not work on one field? As it works fine when i specify the field just not when i want it to work on multiple.
The change you need to make is to add a second parameter to update(), say field, and then pass that to parseResponse().
I am not entirely sure what i need to do here as i just download this from a site and did not build it. I don't really know javascript to well.
See the changes below: - 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);
-
}
-
I am not entirely sure what i need to do here as i just download this from a site and did not build it. I don't really know javascript to well.
Trace your code from the moment the JS function update is triggered. What you need to be checking for is whether or not all the objects being accessed have been passed properly to all the functions that are called after that. Don't be shy to refer to a Javascript functions tutorial while you are at it.
Edit: Too late again
Trace your code from the moment the JS function update is triggered. What you need to be checking for is whether or not all the objects being accessed have been passed properly to all the functions that are called after that. Don't be shy to refer to a Javascript functions tutorial while you are at it.
This is more useful than what I've posted if "teaching a man to fish" is the objective.
Thank you so much, works perfect now :)
Glad it works. I hope you understand why it works too.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dan |
last post by:
Hello all,
I am getting records from a db and displaying the records to the user
through a drop down menu in an asp page.
Each record has 6 fields and I need to display them all to the user in...
|
by: Tony |
last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET
distribution - I'm pretty concerned about this. Does anyone know if this
is the same "prototype.js" that is not well-liked...
|
by: rsteph |
last post by:
I have a javascript drop down menu that I borrowed from a website. It utilizes a little .css to help with formatting. The menu works great, and on all 3 of the browsers I'm concerned about; but I am...
|
by: AndiSmith |
last post by:
Hi guys,
I wondered if anyone could help me with this problem, or even shed some light on the direction I need to take to resolve it? I'm using .NET 2.0 (C# flavor) to build a large user-based...
|
by: tusaar |
last post by:
Hi all
I am in big need for a drop down menu created with php, mysql and ajax. Exactly, I need three drop down menu (Category, Subcategory and Item). The data of each drop down will come from...
|
by: Bob |
last post by:
Hi all,
I'm trying to import data, modify the data then insert it into a new
table. The code below works fine for it but it takes a really long
time for 15,000 odd records. Is there a way I...
|
by: TycoonUK |
last post by:
Hi,
As I do not have IE7 on my computer, I was wondering if there is a
fault in my CSS Menu when using IE7.
Please can someone look at my site - http://www.worldofmonopoly.co.uk
and tell me...
|
by: priscbean |
last post by:
I'm a total newbie. I really need help with this script. Its a drop down menu formatted with a CSS. It's not a formatting issue but i can't get the JS to run. I think I'm having issues calling it or...
|
by: giandeo |
last post by:
Hello all,
It's almost a couple of weeks since i am struggling to get this code work. Unfortunately, i am stuck. There seems to be no hope... Please Help.......
I am working with an asp page...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
| |