Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Only one function is running

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
I am trying show/hide two different layers, it works fine w/ one layer however when i added the second show/hide layer function it shows them both, but on hide it only hides the first one.


Code:
var Loadeditdetails2HTMLHttp = null;
function Loadeditdetails2Html(inteditdetailsId) {
	showhide('LoadingImage2');
	showhide('LoadingDetails');
    Loadeditdetails2HTMLHttp = createRequestObject();
    var url5="/ajax/edit_details.asp?id=" + inteditdetailsId
    Loadeditdetails2HTMLHttp.open('GET', url5, true);
    Loadeditdetails2HTMLHttp.onreadystatechange = getLoadeditdetails2HTMLHttpResponse;
    Loadeditdetails2HTMLHttp.send('');
}

function getLoadeditdetails2HTMLHttpResponse() {
    if (Loadeditdetails2HTMLHttp != null)
        if (Loadeditdetails2HTMLHttp.readyState == 4)
            if (Loadeditdetails2HTMLHttp.status == 200)
                  showhide('LoadingImage2');
                  showhide('LoadingDetails');
				
                document.getElementById('loadeditdetails').innerHTML = Loadeditdetails2HTMLHttp.responseText;	
}


Layer hide code:
Code:
var state = 'hidden';

function showhide(layer_ref) {

if (state == 'visible') {
state = 'hidden';
}
else {
state = 'visible';
}
if (document.all) { //IS IE 4 or 5 (or 6 beta)
eval( "document.all." + layer_ref + ".style.visibility = state");
}
if (document.layers) { //IS NETSCAPE 4 or below
document.layers[layer_ref].visibility = state;
}
if (document.getElementById && !document.all) {
maxwell_smart = document.getElementById(layer_ref);
maxwell_smart.style.visibility = state;
}
}
 
I mentioned in your last post that because of your indentation you appear to be missing a brace.

Could you re-indent your code, or apply missing braces as appropriate? It would really aid anyone trying to help debug this if they didn't have to work out your intent at every line of code.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
N.B... I'm thiinking specifically about this block right now:

Code:
if (Loadeditdetails2HTMLHttp.status == 200)
      showhide('LoadingImage2');
      showhide('LoadingDetails');

Was your intent that both "showhide" calls should run if the status was 200, or just the first, with the second being run all the time?

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yes i want to run both functions one after another... My brackets seem fine... because its the ajax code i have used for over a year, and i dont get any browser erros other then this occasion
 
Okay now its showing the first layer, not showing the second and the first layer is not hiding you'll have to forgive because my javascript is just not that good... but i get by you could say... I am going off the browser errors, if the browser doesnt error... i think my js is good to go...


Code:
var Loadeditdetails2HTMLHttp = null;
function Loadeditdetails2Html(inteditdetailsId) {
	showhide('LoadingImage2');
	showhide('LoadingDetails');
    Loadeditdetails2HTMLHttp = createRequestObject();
    var url5="/ajax/edit_details.asp?id=" + inteditdetailsId
    Loadeditdetails2HTMLHttp.open('GET', url5, true);
    Loadeditdetails2HTMLHttp.onreadystatechange = getLoadeditdetails2HTMLHttpResponse;
    Loadeditdetails2HTMLHttp.send('');
}

function getLoadeditdetails2HTMLHttpResponse() {
    if (Loadeditdetails2HTMLHttp != null)
        if (Loadeditdetails2HTMLHttp.readyState == 4)
            if (Loadeditdetails2HTMLHttp.status == 200) {
				showhide('LoadingImage2');
				showhide('LoadingDetails');
			}
                document.getElementById('loadeditdetails').innerHTML = Loadeditdetails2HTMLHttp.responseText;	
}
 
showhide() toggles the contents of "state", a global variable. Not the same thing as toggling the display state of each specific layer. (If you try three layers the hide mechanism should work for the 1st and 3rd.)

To fix your function attach a state variable to each layer or use the display attribute of each layer's style object.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top