i have written two separate function in javascript and i hava created a global variable.
first function is set the value of global variable and the second function is used that global variable to check the condition but it doesn’t work.
here is my code.
var flag = 1;
function setSelection(){
for (index=0; index < top.parent.frmRadio.view.length; index++) {
if (top.parent.frmRadio.view[index].checked) {
var radioValue = top.parent.frmRadio.view[index].value;
if(radioValue == "graph"){
flag = 1;
top.parent.test2.innerHTML = flag;
}
else{
flag = 0;
top.parent.test2.innerHTML = flag;
}
}
}
}
function setFileName(name){
var fileName = name;
// document.getElementById("body").innerHTML = fileName;
document.getElementById("body").innerHTML = flag;
if(flag == 1){
top.parent.frame2.location = fileName;
document.getElementById("body").innerHTML = fileName;
}
else{
top.parent.frame2.location = "simpletree.html";
document.getElementById("body").innerHTML = "simpletree.html";
}
// parent.frame2.location = fileName;
}
both the function are called by different place. first method is called when radio button is clicked and second when list is clicked.
Your global variable is fine (to the extent that global variables are fine; strongly recommend avoiding them).
I think the problem is in the
setFileNamefunction, you have some very odd-looking operations there. Some comments:Setting the
innerHTMLof an element changes its contents to the actual text you assign. It doesn’t load a page and put the page’s content there. For that, you’d have to use aniframeor use ajax to load the page content (from a server on the same origin) and then assign the resulting text/markup.