Consider this HTML:
<input type="text" name="userinput[]" />
<input type="text" name="userinput[]" />
<a href="javascript:void(0);">More</a>
The intent here is for users to input values into the form fields and, should they want more fields, clicking the link will execute this jQuery:
$('a').click( function(e) {
e.preventDefault();
$(this).before('<input type="text" name="team_names[]" />');
//refocus on the first empty input
$('input[value=""]:first').focus();
});
So "User A" fills in the two form fields, clicks the "More" link, two more input fields are added and the browser focuses on the third overall field (due to it being the first empty field). Unfortunately, the code selects the first overall field. I can make it focus on the last input field... no problem... but if the user clicks "More" multiple times before filling in additional fields, I still want to focus on the first empty field.
What am I missing?