Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 76267

Repeat a JavaScript result that is being displayed with again on the same page

$
0
0

The scenario, I have several JavaScript calculations (based on user input) on my page. The results of which are displayed via <span id="x"></span> for example..

document.getElementById("x").innerHTML = +(Math.round(document.form.input.value /25.4 + "e+2")  + "e-2");

My question is how best to display the result if I want to use it again later in the same page.

I have tried just using <span id="x"></span> again later in the page but because the "id" is the same this doesn't work so my current workaround is just to simply repeat the JavaScript calc again and then call it again with "2" on the end like so..

<span id="x2"></span>

document.getElementById("x2").innerHTML = +(Math.round(document.form.input.value /25.4 + "e+2")  + "e-2");

but this has resulted in a lot of repeated/unnecessary extra calculations and I can't help but think there must be a simpler way to repeat the result later on in the same page?


Viewing all articles
Browse latest Browse all 76267

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>