Get total number of elements in array of textbox

September 12th, 2015 jQuery 1,465 views

This situation basically happens when we create a Array of elements that gets submitted using PHP. And the input values gets retrieved using $_POST variable in array format. I made an interface where I created html form with one textbox as telephone_no with a button Add more. When I click this button, it generates a new textbox element with same name telephone_no. I wanted to submit them as PHP array variable, so I write textbox element name as telephone_no[].  So the textbox elements in HTML code looks like this :

On the backend, I made a PHP script to catch all these telephone numbers using $_POST[‘telephone_no’] array variable. But on frontend, I also wanted to calculate how many telephone numbers were added, which can be done using jQuery.  But if you do it like below, it returns only 1 in place of 5 elements.
So I used below code which worked perfectly.
Leave your comments: