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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:07:14+00:00 2026-05-28T00:07:14+00:00

I got this $(‘#password’).change(function() { var toSha1 = $(‘#msisdn’).val() + $(‘#password’).val(); var authCode =

  • 0

I got this

$('#password').change(function() {
    var toSha1 = $('#msisdn').val() + $('#password').val();
    var authCode = $.sha1(toSha1);
});

How can I make the variable authCode to be visible in the whole script. For example this to work properly:

  $('#password').change(function() {
    var toSha1 = $('#msisdn').val() + $('#password').val();
    var authCode = $.sha1(toSha1);
});
 alert(authCode);

I’ve tried by defining it without the keyword “var” but it seemed not to work.

EDITED: here’s the source

<div data-role="content">
    <textarea id='resultArea'></textarea>
    <label for='msisdn'>MSISDN:</label>
    <input type='text' id='msisdn' value='+359899888777'>
    <label for='authCode'>authCode:</label>
    <input type='text' id='authCode' value='8bcac5dabf06219843a5a3b755c47e69600e050a'>
    <label for='password'>Password:</label>
    <input type='password' id='password' value='123'>
    <button data-role='button' data-inline='true' data-theme='e' id='register'>Register</button>
    <button data-role='button' data-inline='true' data-theme='e' id='login'>Login</button>
</div><!-- /content -->
<script>
$('#resultArea').hide();
$('#password').change(function() {
    var toSha1 = $('#msisdn').val() + $('#password').val();
    window.authCode = $.sha1(toSha1);
});
alert(window.authCode);
</script>
  • 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-28T00:07:15+00:00Added an answer on May 28, 2026 at 12:07 am

    To make it a global explicitly:

    window.authCode = $.sha1(toSha1);
    

    Global variables are properties of the window object.

    Note that there’s a separate issue with your code, though: You’re alerting the value of authCode immediately after hooking up the handler, rather than when the change event fires. See the comments:

    $('#resultArea').hide();               // Happens immediately
    $('#password').change(function() {     // change() call happens immediately, setting up the handler
        // ...but this code runs when the handler is *called*, not inline with the code above and below
        var toSha1 = $('#msisdn').val() + $('#password').val();
        window.authCode = $.sha1(toSha1);
    });
    alert(window.authCode);                // Happens immediately after the calls above
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got this flash application where you can click a link while watching a
Got this function for ammending the query string and was wondering what the replacement
I got this for IE browsers, var IE = /*@cc_on!@*/false; if (IE) { //
I got this odd error and I can't figure out where it came from:
Got this regex string from JavaScript: the good parts (pp. 66). Can't get it
Got this really stupid problem: Can find the proper name for the android folder
Got this simple piece of html code and I want to make the TEST
I got this function which is a private boolean function that checks if there
I got this for(m in _data.data) { var _person= new Person(_data.data[m].Properties); //return a person
Got this line of code here but its not working. private void Button_Click(object sender,

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.