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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:46:52+00:00 2026-05-30T07:46:52+00:00

I have a table in a cell that displays the numbers a user enters

  • 0

I have a table in a cell that displays the numbers a user enters with buttons (using onclick and a showthis function. I need to be able to store the value as a variable in order to perform operations on it. How can I do this?
PS: I am using JavaScript and HTML

<script language="JavaScript" type="text/javascript"> 
    function showthis(first){ 
        document.getElementById("displaycell").innerHTML+=first; 
    } 
</script>
<body> 
  <h1 align="center"> RPN Calculator </h1>
  <table summary align="center" border="1" cellpadding="1" cellspacing="3">
    <tr>
      <th id="displaycell" colspan="5" type="text"> </td>
    </tr>
    <tr>
      <td>
        <button type="button" onclick="showthis('1')">1</button>
      </td>
      <td>
        <button type="button" onclick="showthis('2')">2</button>
      </td>
      <td>
        <button type="button" onclick="showthis('3')">3</button>
     </td>
     <!-- ... -->
  • 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-30T07:46:53+00:00Added an answer on May 30, 2026 at 7:46 am

    Firstly you should not be using += with innerHTML. It means that you will end up with the numbers appending to the cell’s internal value rather than overwriting it.

    function showthis ( number ) {
        var cell = document.getElementById('displaycell');
        cell.innerHTML = "";
        cell.appendChild( document.createTextNode( number ));
    }
    

    Would be a much better way to handle that.

    Next, within showthis you are best off storing the value in a variable so that you can access it directly from javascript in the future.

    var displayStore = 0;
    
    function showthis ( number ) {
        var cell = document.getElementById('displaycell');
        cell.innerHTML = "";
        cell.appendChild( document.createTextNode( number ));
    
        // you can either do this in a variable local to the <td> DOM Object like so
        cell.currentDisplayNumber = number;
    
        //or in a global variable like so
        displayStore = number;
    }
    

    Finally, to access that variable again you can either read it out of the displaystore <td> or read it from your variable.

    function DoStuff0 () {
        var number = Number( document.getElementById( 'displaycell' )).innerHTML;
        // rest
    }
    
    function DoStuff1 () {
        var number = document.getElementById('displaycell').currentDisplayNumber;
        // rest
    } 
    
    function DoStuff2 () {
        var number = displayStore;
        // rest
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that displays cell using UITableViewCellStyleSubtitle: ============================================================= Title:This is the title
I have a custom Table View Cell that displays the details of a Conference
I have a table cell that isn't entirely filled with text so the bg
I have a UIButton that is created inside of each table cell. I want
I have a class A that inherits UITableViewCell (to customize a table cell). It
I have the following code that produces a background image in a table cell.
On each cell of my table view I want to have a bar that
I have a table cell, and when the user clicks on it, I replace
I have a table that displays a column of test names, with several (unlimited
I have a Table that is generated using a SQL Database And put into

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.