TL; DR
- Mark the example in chrome.
- Enter the text and press
tab. see one new window. - enter something and press
enter. see two new fields where expected.
Introduction
I noticed that when using enterinstead of tabchanging fields, my exchange function in the input field worked twice. This page was quite large and still in development (read: numerous other errors), so I made a minimal example demonstrating this behavior, in which case it even does it on a tab. As far as I know, this is a problem only in Chrome .
What should he do?
I want to make a new input after something is entered in the input field. This field should be focused.
Example:
javascript - need jquery
function myOnChange(context,curNum){
alert('onchange start');
nextNum = curNum+1;
$(context.parentNode).append('<input type="text" onchange="return myOnChange(this,'+nextNum+')" id="prefix_'+nextNum+'" >');
$('#prefix_'+nextNum).focus();
return false;
}
HTML part
<div>
<input type="text" onchange="return myOnChange(this,1);" id="prefix_1">
</div>
full pastebin code . you need to add your jquery path to the script
A working example is presented here by jFiddle
Onchange is called twice: the function is called myOnChange, makes a new input, calls focus(), myOnChangeis called again, creates a new input, "internal" myOnChangeexits and then "external" exits myOnChange.
I assume this is due to the fact that a change in focus causes onchange()?. I know that there is a difference in behavior between browsers.
.focus() ( ), onchange(), myOnChange() . - ?