Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4537172
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:38:17+00:00 2026-05-21T14:38:17+00:00

i have written two separate function in javascript and i hava created a global

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:38:18+00:00Added an answer on May 21, 2026 at 2:38 pm

    Your global variable is fine (to the extent that global variables are fine; strongly recommend avoiding them).

    I think the problem is in the setFileName function, you have some very odd-looking operations there. Some comments:

    function setFileName(name){
        var fileName = name;
    //  document.getElementById("body").innerHTML = fileName;
        document.getElementById("body").innerHTML = flag;
    //  ^-- Do you *really* have an element on the page with the id="body"?
    //      This will not change the `body` element of the page (unless you've given it that id).
        if(flag == 1){
            top.parent.frame2.location = fileName;
            document.getElementById("body").innerHTML = fileName;
    //      ^--- This will replace the content of the element with id="body" with
    //           the text of the filename (it will not retrieve the file)
        }
        else{
            top.parent.frame2.location = "simpletree.html";
            document.getElementById("body").innerHTML = "simpletree.html";
    //      ^--- This will replace the contents of the element with id="body"
    //           with the text "simpletree.html", it will not retrieve the file
        }
    
    
    //  parent.frame2.location = fileName;
    } 
    

    Setting the innerHTML of 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 an iframe or use ajax to load the page content (from a server on the same origin) and then assign the resulting text/markup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have two applications written in C#. The first is a third party
I have written a set of two predicates to test whether a number is
I have written a function that takes two arguments and returns a SETOF result.
I have written this function that will give me a monthly sum for two
I have two buttons: btnAdd and btnUpdate . I have written a jquery function
I have two applications written in Java that communicate with each other using XML
Here's the thing: I have two applications, written in C++ and running on two
Hypothetically, you have two products, one written in Java, the other in C#. You
So my problem is that I've written a function that takes two Doubles, two
Okay, I have two different background .jpgs that I want to used as the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.