Search blog

Monday, April 23, 2018

[SOLVED] - How to Enter Floating-Point/Decimal Numbers in HTML5 Forms

If you have a form where you have declare a input type as below:
 <input type="number" name="quantity" min="1" max="5">  

Now if you enter a floating-point/decimal value like '2.1' and try to process your form then you will get the following error message:

"Please enter a valid value. The two nearest valid values are 2 and 3."

How to Enter Floating-Point/Decimal Values in HTML5 Forms
Click on image to enlarge
Solution:
To solve this just add
step="any"
to your form. So, your input code should be as follows:
 <input type="number" name="quantity" min="1" max="5" step="any">  

Now, you should be able to enter decimal/floating-point values and process them without any hassle.

Sunday, April 15, 2018

Why NOT to Use var and Instead Use let or const in JavaScript

Consider the following example code:


You can note that the value of var a has changed due to the assignment within the block scope of the if statement, while the value of let b & const c value have remained unaffected.

So, the way let & const works is the way most programming languages work.

var is kind of weird, it’s one of the things a lot of people didn’t like about JavaScript. It causes security risk and confusion and hence it’s better to avoid it.

Friday, April 6, 2018

Why You Shouldn't Be Using mysqli_fetch_array()?

While researching as to why not to use mysqli_fetch_array(), and instead use mysqli_fetch_row() or mysqli_fetch_assoc(), I ran into this old post, which well explains the reason. The test results for each of these functions may not be as per contemporary test case, but it will still give you a good idea as to why mysqli_fetch_array() shouldn't be used

Benchmark on a table with 38567 rows:

mysql_fetch_array
MYSQL_BOTH: 6.01940000057 secs
MYSQL_NUM: 3.22173595428 secs
MYSQL_ASSOC: 3.92950594425 secs

mysql_fetch_row: 2.35096800327 secs
mysql_fetch_assoc: 2.92349803448 secs

As you can see, it's twice as efficient to fetch either an array or a hash, rather than getting both.  It's even faster to use fetch_row rather than passing fetch_array MYSQL_NUM, or fetch_assoc rather than fetch_array MYSQL_ASSOC.

Don't fetch BOTH unless you really need them, and most of the time you don't.

SOURCE: http://bit.ly/2qaSyFr

Top 5 Posts (Weekly)