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 8610705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:11:37+00:00 2026-06-12T04:11:37+00:00

Please see the following code. After I clicked the button PUT VAR, the alert

  • 0

Please see the following code.
After I clicked the button “PUT VAR”, the alert always shows me the value “putted!!” when I click the button “SHOW VAR”.
Does this mean that I can use global variables as hidden values on the page?

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript"> 
var test_var = "default";
$(function(){
    $("#show_var").on("click", function(){
        alert(test_var);
    });

    $("#put_var").on("click", function(){
        test_var="putted!!";
    });
});
</script>
</head>
<body>
<div id="demo">
<input type="button" value="SHOW VAR" style="width:100px" id="show_var" />
<input type="button" value="PUT VAR" style="width:100px" id="put_var" />
</div>
</body>
</html>
  • 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-06-12T04:11:38+00:00Added an answer on June 12, 2026 at 4:11 am

    Variables are stored as long as the context in which they were created is valid. Essentially

    var test_var = value
    

    outside of any closure is the same as

    window.test_var = value.
    

    The window object gets destroyed after a unload event, so as long as you stay in the same document context your variables are stored.

    So, yes, you can use them as hidden values, but you should use <input type="hidden"> for form values.

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

Sidebar

Related Questions

Please see the following code: List list = Collections.synchronizedList(new ArrayList()); // ... synchronized (list)
How do we update a textbox on ticking checkboxes? Please see the following code,
Please see the following code: def good(): foo[0] = 9 # why this foo
Please see the the following http://valogiannis.com/recent/ .I have a webpage and when user click
Please see my code below. The goal is the following. When a user presses
Please see the following code to understand my question better. class compareByValue { public:
Please see my following code snippet. @Transactional public void saveMembersService(List<Member> list1, List<Member> list2) {
Please see the following t-sql code DECLARE @iError INT EXEC('select * from sysobj') SELECT
Please see following methods. public static ProductsCollection GetDummyData(int? customerId, int? supplierId) { try {
Please see following examples first, and which one is better? Could you compare some

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.