kellybelly
asked on
event handler scripted rather than in HTML tag
if this works:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -
<select name="client" onChange="change(this);" size="8" style="width:165px"></sele ct>
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -
to call the function change with the object reference to the selected value, then why won't this:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- -
document.criteria.client.o ptions[doc ument.crit eria.clien t.options. length - 1].onClick=populate();chan ge(this);
or this:
document.criteria.client.o ptions[doc ument.crit eria.clien t.options. length - 1].onClick=populate();chan ge(documen t.criteria .client.op tions[docu ment.crite ria.client .options.l ength - 1]);
I need to pass a reference to the selected index to the change function on click. Please advise. Thanks.
--------------------------
<select name="client" onChange="change(this);" size="8" style="width:165px"></sele
--------------------------
to call the function change with the object reference to the selected value, then why won't this:
--------------------------
document.criteria.client.o
or this:
document.criteria.client.o
I need to pass a reference to the selected index to the change function on click. Please advise. Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Show small sample of code that doesn't work, or post a link
ASKER
//populate client and location boxes - called onLoad
function populate(){
clearCombo();
clearTemp();
//populate client selections
for (var i = 0; i < client_array.length; i++){
document.criteria.client.o ptions[doc ument.crit eria.clien t.options. length] = new Option(clientName_array[i] , client_array[i]);
document.criteria.client.s ize = 8;
};
//populate country selections
for (var i = 0; i < country_array.length; i++){
document.criteria.country. options[do cument.cri teria.coun try.option s.length] = new Option(country_array[i], country_array[i]);
document.criteria.country. size = 5;
};
//populate style selections
for (var i = 0; i < style_array.length; i++){
document.criteria.style.op tions[docu ment.crite ria.style. options.le ngth] = new Option(style_array[i].text ,style_arr ay[i].styl e);
document.criteria.style.si ze = 5;
};
for (var i = 0; i < document.criteria.length - 1; i++){
selected_array["'" + document.criteria[i].name + "'"] = undefined;
document.getElementById(do cument.cri teria[i].n ame + "P").style.display = 'none';
document.criteria[i].disab led = false;
};
document.getElementById('s electedCel l').style. display = 'none';
document.getElementById("c ritThumbsR ow").style .display = 'none';
document.getElementById("c ritThumbsP ").innerHT ML = '';
};//end populate function------------------ ---------- ---------- ---------- ---------- --------
function change(t){//change 'selected array' and SELECTED text at top of page - populate combo boxes based on selection
nm = 'city'; clearBox();//clear city and state boxes, and make them disappear
nm = 'state'; clearBox();
nm = t.name; val = t.value
selected_array[nm] = val//assign value to selected_array[this.name]
document.getElementById('s electedCel l').style. display = 'block'//populate SELECTED text section
document.getElementById(nm + "P").style.display = 'block'
document.getElementById(nm + "P").innerHTML = val
if ( nm == 'client' ){//if client is chosen get formal client name for 'SELECTED' text at top and change all other combo boxes accordingly
clearBox();
for (var i = 0; i < client_array.length; i++){
if ( client_array[i] == val) {
document.getElementById(nm + "P").innerHTML = clientName_array[i];
//put chosen criteria at the top of the list for that form element, space, then ALL other choices
document.criteria.client.o ptions[0] = new Option (clientName_array[i],val);
document.criteria.client.o ptions[1] = new Option (" ", " ");
};
document.criteria.client.o ptions[doc ument.crit eria.clien t.options. length] = new Option (clientName_array[i], client_array[i]);
document.criteria.client.s ize = 8;
document.criteria.client.o nChange = function(){
populate();
change(this);
}; };
style();
country();
};
if ( nm == 'style' ) {
clearBox();
for (var i = 0; i < style_array.length; i++){
if ( style_array[i].style == val) { //change style options
document.getElementById(nm + "P").innerHTML = style_array[i].text;//get lighting style name instead of shortened version from select box and populate SELECTED text section
//put chosen criteria at the top of the list for that form element, space, then ALL other choices
document.criteria.style.op tions[0] = new Option (style_array[i].text,style _array[i]. value);
document.criteria.style.op tions[1] = new Option (" ", " ");
};
document.criteria.style.op tions[docu ment.crite ria.style. options.le ngth] = new Option (style_array[i].text, style_array[i].illuminatio n);
document.criteria.style.si ze = 5
};
client();
country();
document.criteria.style.on Change = function(){
populate();
change(this);
}; };
if (nm == 'country'){
clearBox();
document.criteria.country. options[0] = new Option (val,val);
document.criteria.country. options[1] = new Option (" ", " ");
for (var i = 0; i < country_array.length; i++){
document.criteria.country. options[do cument.cri teria.coun try.option s.length] = new Option (country_array[i], country_array[i]);
};
client();
style();
document.criteria.country. onChange = function(){
populate();
change(this);
}; };
if ( nm =='city' ) {
document.getElementById("c ityP").sty le.display = 'block'
document.getElementById("c ityP").inn erHTML = val
client();
style();
country();
document.criteria.city.onC hange = function(){
populate();
change(this);
}; };
if ( nm == 'state' ) {
document.getElementById("s tateP").st yle.displa y = 'block'
document.getElementById("s tateP").in nerHTML = val
client();
style();
country();
document.criteria.state.on Change = function(){
populate();
change(this);
}; };
function populate(){
clearCombo();
clearTemp();
//populate client selections
for (var i = 0; i < client_array.length; i++){
document.criteria.client.o
document.criteria.client.s
};
//populate country selections
for (var i = 0; i < country_array.length; i++){
document.criteria.country.
document.criteria.country.
};
//populate style selections
for (var i = 0; i < style_array.length; i++){
document.criteria.style.op
document.criteria.style.si
};
for (var i = 0; i < document.criteria.length - 1; i++){
selected_array["'" + document.criteria[i].name + "'"] = undefined;
document.getElementById(do
document.criteria[i].disab
};
document.getElementById('s
document.getElementById("c
document.getElementById("c
};//end populate function------------------
function change(t){//change 'selected array' and SELECTED text at top of page - populate combo boxes based on selection
nm = 'city'; clearBox();//clear city and state boxes, and make them disappear
nm = 'state'; clearBox();
nm = t.name; val = t.value
selected_array[nm] = val//assign value to selected_array[this.name]
document.getElementById('s
document.getElementById(nm
document.getElementById(nm
if ( nm == 'client' ){//if client is chosen get formal client name for 'SELECTED' text at top and change all other combo boxes accordingly
clearBox();
for (var i = 0; i < client_array.length; i++){
if ( client_array[i] == val) {
document.getElementById(nm
//put chosen criteria at the top of the list for that form element, space, then ALL other choices
document.criteria.client.o
document.criteria.client.o
};
document.criteria.client.o
document.criteria.client.s
document.criteria.client.o
populate();
change(this);
}; };
style();
country();
};
if ( nm == 'style' ) {
clearBox();
for (var i = 0; i < style_array.length; i++){
if ( style_array[i].style == val) { //change style options
document.getElementById(nm
//put chosen criteria at the top of the list for that form element, space, then ALL other choices
document.criteria.style.op
document.criteria.style.op
};
document.criteria.style.op
document.criteria.style.si
};
client();
country();
document.criteria.style.on
populate();
change(this);
}; };
if (nm == 'country'){
clearBox();
document.criteria.country.
document.criteria.country.
for (var i = 0; i < country_array.length; i++){
document.criteria.country.
};
client();
style();
document.criteria.country.
populate();
change(this);
}; };
if ( nm =='city' ) {
document.getElementById("c
document.getElementById("c
client();
style();
country();
document.criteria.city.onC
populate();
change(this);
}; };
if ( nm == 'state' ) {
document.getElementById("s
document.getElementById("s
client();
style();
country();
document.criteria.state.on
populate();
change(this);
}; };
There are other functions and Array objects referenced for which we have no code. Could you give us a link to this, so we can debug easily?
ASKER
local.colite.com/web/led/l ocator.asp
it's very complicated code (sorry) - it's javascript written by ASP with live info from databases. The code you are looking for should be around line # 750
it's very complicated code (sorry) - it's javascript written by ASP with live info from databases. The code you are looking for should be around line # 750
ASKER
Please help. I still need to figure out why the function reads the second outside function call, but not the first (it sees change() but bot populate()).
I get an error here in the showPhoto function:
str.replace([\/], "\/");
and I get populate is not defined, so the function has some error I guess.
str.replace([\/], "\/");
and I get populate is not defined, so the function has some error I guess.
ASKER
let me upload some new code - sorry I had uploaded some bad code.
ASKER