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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:07:10+00:00 2026-05-31T04:07:10+00:00

This is my javascript code: var num1; function press_Button(){ num1 = 3; } Then

  • 0

This is my javascript code:

var num1;
function press_Button(){
    num1 = 3;           
}

Then I have a button with this: onclick="press_Button()"

and in the HTML is this:

<script type="text/javascript">
    document.write(num1);
</script>

The page displays the variable as undefined, even after hitting the button, and I can’t figure out why.

Help!

  • 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-31T04:07:12+00:00Added an answer on May 31, 2026 at 4:07 am

    You’ll need to update the display of num1 after you call press_Button. What I would do is ditch the document.write, and instead make a span:

    <span id="num1Display"></span>
    

    And then:

    function press_Button() {
        num1 = 3;           
        document.getElementById("num1Display").textContent = num1;
    }
    

    Or, if you need this to work on ancient browsers that don’t like textContent, you could do:

    function press_Button() {
        num1 = 3;           
        document.getElementById("num1Display").innerHTML = num1;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code: <script type=text/javascript> var maxLength=10; function charLimit(el) { if (el.value.length >
I have this JavaScript code: <script type=text/javascript> function timeMsg() { var t=setTimeout(doRedirect(),10000); } function
This is my code: <html> <script type=text/javascript> var data1 = $100; var data2 =
I have this javascript code <Script> function getGroupId(){ var group=document.getElementById(selectedOptions).value; var groupFirstLetter=group.substring(2); } </Script>
This is my JavaScript code: <script> function change(name){ var element = document.all.name.value; } </script>
I have this javascript code: $(document).ready(function() { var leftHeight = $('#maincontent').height(); $('#sidemenu').css({'height':leftHeight}); }); This
I have some troubles with this small JavaScript code: var text=Z Test Yeah !
I have this javascript code: $(function(){ var currentCarouselItem = 1; //set carousel to first
I have this javascript code : function showMyVideos(data) { var feed = data.feed; var
I have this javascript code which works fine var QuestionID = panel.siblings('.QuestionIDWrapper').children('input[type=hidden]').val(); but if

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.