Maintaining and refreshing the content in an input field

I'm currently working on a JavaScript program that aims to update the value of a hidden input field.

However, I am facing an issue where a specific value is being changed too frequently. To address this, I have attempted using the following method to store the previous value:

<input type="hidden" value="" id="test">

<script>
alert(document.getElementById('test').value);
document.getElementById('test').innerHTML=10;
alert(document.getElementById('test'));
</script>

The problem is that '10' is not being stored. How can I fix this issue? My main objective is to simultaneously keep track of the previous value (as well as the last 'n' values changed) and the updated value. If there are alternative methods to achieve this goal, I would greatly appreciate any suggestions.

Answer №1

Give this example a shot:

alert(document.getElementById('try').value);
document.getElementById('try').value = "10";
alert(document.getElementById('try').value);

http://jsfiddle.net/HTq8J/

Answer №2

Give this a shot:

<input type="hidden" value="" id="trial">

<script>
  alert(document.getElementById('trial').value);
  document.getElementById('trial').value = '5';
  alert(document.getElementById('trial').value);
</script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the process for reverting variables back to their original values using pure Javascript?

I am working on developing a hangman game using vanilla javascript and I need some assistance with resetting the game after a player loses. Specifically, I would like to: 1. Reset the "guessRemain" variable. 2. Clear out the "guess" id so that none of the ...

Node JS | Error: Unable to access the property 'first_name' of an undefined object

Just getting started with my MEAN application and I've hit a roadblock while trying to add data to the database. Can someone please help me find a solution for this? This is the main file, the entry point of the application. //Importing modules var ...

What is the method for assigning 'selective-input' to a form field in Angular?

I am using Angular and have a form input field that is meant to be filled with numbers only. Is there a way to prevent any characters other than numbers from being entered into the form? I want the form to behave as if only integer keys on the keyboard ar ...

Build a new shop using a section of data from a JSON database

Let's say I have a JSON store that is set up as shown below var subAccountStore = new Ext.data.JsonStore({ autoLoad: true, proxy: { type:'ajax', url : '/opUI/json/subaccount.action?name="ABC"' }, fields: ['acc ...

Understanding the response of AJAX in PHP

After exploring different ways for jQuery to interpret data in an AJAX call, I found that using JSON may be too complex for my needs. The PHP script I'm working with always returns a single integer string, sometimes followed by one or two additional ...

AngularJS - displaying a notification when the array length is empty and customizing the visibility to conceal the default action

I've been working on an Angular project where I display a loading circle that disappears once the content is loaded. This circle is simply a CSS class that I call from my HTML only when the page first loads, like this: Actually, the circle consists o ...

Authentication in Feathers JS without the need for email addresses

Currently, I am in need of an authentication system for my dApp that operates without using email addresses or storing any user information. What I require is an endpoint where users can submit a seed phrase and password to generate a JWT. The process shou ...

The array is not receiving the objects as intended

I'm facing an issue with my event listener that is supposed to push new messages to an array, but it seems to only be pushing the strings. Here is the code snippet: async function consume() { try { let result = []; const connection = await a ...

Choose a particular form when the dropdown option is changed

I have two forms that I would like to display based on the selection from a dropdown menu. For example, if "Form1" is selected from the dropdown, then Form1 should be displayed. If "Form2" is selected, then Form2 should be displayed. Can anyone suggest h ...

Issue with HTTP POST Headers in XmlHttpRequest

I am currently attempting to pass a string using the XmlHttp method. Let me provide you with the code for better understanding: HTML <div id="greetings"> You are voting out <b style="color: #00b0de;" id=roadiename></b>. Care to explain ...

The JQuery function .remove() will not properly remove dynamically added elements

I am facing an issue when trying to remove an element from a page. Every time I click on a button on the page, it adds a div with the following structure: <div class="holder-div" style="position: relative;display: inline-block;"> ...

Trouble with bootstrap 5 nested accordions: panels won't collapse as expected

I've structured my page content using nested bootstrap accordions within Bootstrap 5. The primary accordion is organized by continents, with each panel containing a secondary accordion for individual countries. While the main accordion functions cor ...

Is there a way for me to gain access to the ng-repeat scope?

I have a scenario where my ng-repeat generates different elements and I need to perform certain operations, such as creating variables, within the scope of the ng-repeat. Is there a way to access the specific ng-repeat scope? How can I achieve something ...

Creating HTML elements dynamically with attributes based on the `as` prop in React using TypeScript

Is there a way to dynamically create HTML elements such as b, a, h4, h3, or any element based on the as={""} prop in my function without using if guards? I have seen a similar question that involves styled components, but I am wondering if it can be done ...

Just built a React App including a blog functionality, but for some reason the blog posts are not showing up. Any suggestions on how to fix this issue

I'm currently working on a project that involves creating a blog page for our react app. Despite my efforts, I am facing difficulty in getting the blog posts to show up. In order to retrieve all the posts from my MYSQL database, I have set up an API ...

Conversing about the user data modeling in MongoDB

Here's a question for you: Is it a better idea to separate the users' model into one for storing passwords for access, and another for profile information? Or is it more secure to have everything together in one model? What are your thoughts on t ...

The function Event.preventDefault seems ineffective when attempting to block input of CJK (Korean) characters in a v-text-field of type

Currently, I am tackling an issue in a Vue project where I need to fix a small bug. However, the solution seems quite challenging. I have managed to make the v-text-field accept only numerical input, which is functioning well. <v-text-field type=" ...

Struggling to verify HTTP GET Request in Node.js with Express.js authentication

Attempting to send data via a Get Request, the recipient is utilizing basicauth-middleware for authentication purposes. Authentication through the browser and within the original program (without sending data) is successful, with a confirmation message ind ...

Find any consecutive lowercase or uppercase letter and include one more

I have a task in Javascript that I need help with. The goal is to insert a special character between a lowercase and uppercase letter when they are matched together. For example: myHouse => my_House aRandomString => a_Random_String And so on... T ...

Order JSON object based on designated Array

I'm looking to organize a JSON object in a specific order, Here is the current object structure: { "you": 100, "me": 75, "foo": 116, "bar": 15 } I would like to rearrange this object in the following sequence ['me', 'foo', &apos ...