using javascript calculated values in less
Simply use string interpolation and then escape from the string using ~
:
@winheight:`$(window).height()`;
height: ~"@{winheight}px";
Calculate value in array under certain condition
Just check the last value of the result set.
const
array = [1, 3, 5, 7, 9, 11, 8, 10, 13, 15],
minTen = array.reduce((accu, value) => {
if (accu[accu.length - 1] < 10) accu[accu.length - 1] += value;
else accu.push(value);
return accu;
}, []);
console.log(minTen); // [25, 11, 18, 13, 15]
Javascript calculate sum unless it is less than zero
You could take Math.max
along with zero.
a = Math.max(b * 100 / c, 0);
Auto Calculate with already given value
You're attempting to calculate things using the element, not its value.
Replace
var initialcost = document.getElementById("initialcost");
with
var initialcost = parseFloat(document.getElementById("initialcost").value);
Example with automatic recalculation to boot:
var initialCostElement = document.getElementById("initialcost");
function compute() {
var initialcost = parseFloat(initialCostElement.value);
var Tfee = initialcost - (initialcost * 5)/100;
document.getElementById("fee").value = +Tfee;
}
initialCostElement.addEventListener("input", compute, false);
compute();
<input type="number" value="1000" id="initialcost">
<input type="text" readonly="readonly" id="fee">
Javascript calculations holding variables
Here it is:
function Calculate() { var first = document.getElementById('first').value; var sec = document.getElementById('sec').value; var ans = document.getElementById('ans').value;
document.getElementById('ans').value = parseInt(first) + parseInt(sec); document.getElementById('ans2').value = document.getElementById('ans').value; /*document.form1.submit();*/}
<form name="Calcultor" Method="Get" id='form1'>First Number: <input type="text" name="fnum" size="35" id="first">+ Second Number: <input type="text" name="snum" size="35" id="sec"> <br> <br>Answer: <input type="text" name="ans" size="35" id="ans" /> <input type="text" name="ans2" size="35" id="ans2" /> <button type="button" onclick="Calculate();">Calculate</button></form>
Related Topics
Modify the Value of Each Textfield Based on Original Value Using Jquery
Set the Default Save as Name for a an <Embed> or <Iframe> That Uses a Blob
Choosing Mobile Web HTML5 Framework
Change Svg Text to CSS Word Wrapping
Jquery: How to Get Assigned Font to Element
Possible to Fade Out Div Border
Bootstrap 3: How to Make Head of Dropdown Link Clickable in Navbar
How to Do Anything About "Repaints on Scroll" Warning in Chrome for "Overflow:Scroll" Div
Css3 Keyframe Animations: End and Stay on the Last Frame
Capture/Save/Export an Image with CSS Filter Effects Applied
How to Get the Opacity of an Element Using JavaScript
Dynamically Changing Stylesheet Path Not Working in Ie and Firefox
Prevent Select2 from Flipping the Dropdown Upward
JavaScript - Smooth Parallax Scrolling with Mouse Wheel
Play Pause HTML5 Video JavaScript