once the loop exits the i variable contains the number of input fields - so when you reference allInputs[i] you are trying to reference the input field that comes after the last input field and since you haven't added any since you ran the loop that one doesn't exist.

Try referencing this.name instead as at the time the mousedown event occurs this should point to the input field it is triggered on.