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

  • Home
  • SEARCH
  • 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 6661521
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:17:24+00:00 2026-05-26T02:17:24+00:00

I have a global variable called ‘name’, when a user clicks on a button

  • 0

I have a global variable called ‘name’, when a user clicks on a button a text boxes content is queried and ‘name’ is set to the contents then the name gets printed in a different jquery page.

My problem is name is never printed as the name it was set to, it’s always printed as what it was initially set to instead.

Here’s my callback function:

    <script type="text/javascript">
        $("#finalize").click(function(e)
        {
            g_name = "BLAH";
            return true;
        });
    </script>

For simplicity I’ve set the name to just be ‘BLAH’ on the click.

g_name is declared globally (i.e. outside the function scope).

In the other jquery page I have:

document.write('<label for="testname">Name:</label>');
                document.write('<input type="text" name="testname" id="testname" value="');
                document.write(g_name)
                document.write('"/>');

And g_name is always shown as something else, whatever g_name was initially initilized to.

The button whose click callback sets the global variable also transitions the pages if that makes a difference…

edit:

Ok I’ve figured out what was wrong, the global variable was being written down before it was set. Now I’m trying to do this:

        <script type="text/javascript">
            $('#confirmscreen').bind('pageshow',function() 
            {
                document.write('<label for="testname">Name:</label>');
                document.write('<input type="text" name="testname" id="testname" value="');
                document.write(g_name);
                document.write('"/>');

                document.write(g_phonenumber);
            });
        </script>

However jquery doesn’t seem to like using document.write on the ‘pageshow’ event, is there a way I can make this work, that is to say, write out g_name WHEN the page shows and not when the website is loaded up?

  • 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-26T02:17:25+00:00Added an answer on May 26, 2026 at 2:17 am

    Instead of using document.write use the javascript method document.createElement() and use the setAttribute() method to assign the values and attributes to the created element.

    Hope this helps you.

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

Sidebar

Related Questions

I have a global variable I called Y_VAL which is initialized to a value
newSubmitButton = (Button) findViewById(R.id.newPlayerSubmit); Log.v(heeelp,+newSubmitButton); Seems simple enough. I have a global Button variable
Possible Duplicate: How to programmatically set a global (module) variable? I have a class
I have a main.c with a global variable called int countboards . In the
I have a global variable in my javascript, whose value I want to set
I have used a static global variable and a static volatile variable in file
I have a python module that makes use of a huge dictionary global variable,
I have a javascript function (function1) that checks some global variables (can the user
I'm having trouble with global variables in php. I have a $screen var set
I have created a Variable called myDBManager in my AppDelegate: @interface myAppDelegate : NSObject

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.