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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:06:42+00:00 2026-05-26T07:06:42+00:00

Ok so, what I need to do is change some numbers on the screen

  • 0

Ok so, what I need to do is change some numbers on the screen when keys are pressed, i have it working but I’m not happy with it.

I have a input field and a div that is being updated when the value of the input filed changes. I did that so that I would not be constrained by the input field’s blinking carat etc. I don’t want to display the input field at all but when I hide it with CSS or type=”hidden” it no longer works. I was trying to get this working with JS variables but so far have been unsuccessful.

Any ideas?

HTML

<html>
<head>
 <link rel="stylesheet" type="text/css" href="number.css" />
</head>

<body onLoad="focus();myText.focus();changeNumber()">

<div id='number'>

</div>

<input type="text" id="myText" value="1"/>

</body>

<footer>
<script type="text/javascript" src="number.js"></script>
</footer>

</html>

JAVASCRIPT

var myText = document.getElementById("myText");

function changeNumber(){
var userInput = document.getElementById('myText').value;
document.getElementById('number').innerHTML = userInput;
}

// Capture keyDown events
myText.onkeydown = function(e) {
// "34" is the up arrow key
if (e.keyCode == 34) {
    // increment the value in the text input
    myText.value++;
changeNumber()

// "33" is the down arrow key
} else if (e.keyCode == 33 && myText.value > 1) {
    // decrement the value in the text input
    myText.value--;
changeNumber()
}
}

HERE IN THE FINAL FIXED CODE * THANKS GUYS! **

HTML

<html>
<head>
 <link rel="stylesheet" type="text/css" href="number.css" />
</head>

<body onLoad="focus();number.focus();changeNumber()">

<div id='number' value="1">

</div>

</body>

<footer>
<script type="text/javascript" src="number.js"></script>
</footer>

</html>

JAVASCRIPT

var i = parseInt(1);

function changeNumber(){
var userInput = i;
document.getElementById('number').innerHTML = userInput;
}

// Capture keyDown events for document
document.onkeydown = function(e) {
// "34" is the PGUp key
if (e.keyCode == 34) {
    // increment the value in the text input
    (i++);
changeNumber()

// "33" is the PGDown key
} else if (e.keyCode == 33 && i > 1) {
    // decrement the value in the text input
    (i--);
changeNumber()
}

// "66" is the b key
if (e.keyCode == 66){
window.location.reload()
} 

}
  • 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-26T07:06:43+00:00Added an answer on May 26, 2026 at 7:06 am

    The problem with your code is this:

    myText.value--;
    

    and

    myText.value++;
    

    myText is a DOM element, and the value property has a string, not an integer, I’d recommend doing:

    var i = parseInt(myText.value);
    myText.value = (i++);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some images that need to change, based not only on hover, but
I'm using itextsharp to generate the PDFs, but I need to change some text
I'm trying to format some large numbers in scientific format, but I need the
I need to change some text values inside an after effect project file that
I need to change some custom properties values in many files. Here is an
I've got some UITableViewCells that need to change their height depending on the length
I need a function to change the appearance of some elements in my HTML
How to change HTML background with JavaScript Function? I need some simple function to
Overall goal: User enters some number in minutes and I change those numbers from
I have an array of phone numbers and I need to find if a

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.