Skip to content

Category: JavaScript

Increment number by 0.01 in javascript using a loop

Recently, I took over a project where I had to replace numbers starting from 1.xx and ending up at 10 on a page. Initially, the code was:

but the issue with the code was that it was generating number like:

1.1300000000000001
1.1400000000000001
1.1500000000000001
1.1600000000000001
1.1700000000000002
1.1800000000000002
1.1900000000000002
1.2000000000000002
1.2100000000000002
1.2200000000000002

The issue was with the inaccuracy of floating point numbers. To fix this issue I used:

Get URL Parameter through Javascript

Javascript Function

Call function to read Parameters

FileReader with Progress (Pure Javascript)

HTML

CSS:

Javascript:

JSFiddle: https://jsfiddle.net/anshuverma1989/v5f0kzcc/

Javascript – Capture Multiple Form Changes

On page load we can use a JavaScript function to capture the data in the forms – this can be done quite simply with jQuery’s serializeArray()

This assumes each form has a unique id – if your forms don’t have id’s we can modify the code to give the form an id.

Now you can do the following