Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Have a 2 click counters and am wanting to save the overall total based on the day of the week

I have a Codepen https://codepen.io/Jonbeckner/pen/KKewOQq that I am working on. I have 2 click counters that displays an overall total in a box below the click counters. I have placed a button within, that I’d like to have save the total to the corresponding day of the week. I know how to add an event listener for the button but beyond that I am still learning JS.

My ask is this: when

<button class=" button button-save">
                    Save Total
                </button>

is clicked save the overall total

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<p>Total Units =&nbsp;
            <span id="total-units">
                0
            </span>

to the corresponding day of the week. The total for Monday would display under M Tuesday under T and so forth.

I grabbed the current click counter from Codepen and have added to and modified it to my need thus far. I am still learning JS so please excuse my beginner knowledge.

>Solution :

With no framework, just plain HTML+JS, you can change text of an element in response to a button click like this, by setting its innerText.

document.getElementById('save').addEventListener('click', () => {
  document.getElementById('total-units').innerText = '42';
});
<button id="save" class=" button button-save">Save Total</button>
<p>Total Units = <span id="total-units">0</span></p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading