user558134
user558134

Reputation: 1129

Jquery create text input element and append to form "field focus" does not work in Firefox -problem

I have the following code (see below) which makes the field focus on the inserted text input. But this does not work in Firefox. So I cannot type any text in Firefox.

$('<input/>').attr({ type: 'text', id: 'test', name: 'test' }).appendTo('#form');

Is there any fix for this?

Thanks in advance!

--

Correction to my question

I found out that the problem is caused by

$(selector).sortable().disableSelection()

The only resolution I have now is to not call

//disableSelection()

Any other suggestions are more then welcome.

Upvotes: 8

Views: 29655

Answers (3)

Webomatik
Webomatik

Reputation: 836

This works just fine with Firefox 45:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>Javascript/jQuery Tests</title>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.3.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
    $('<input/>').attr({ type: 'text', id: 'test', name: 'test' }).appendTo('#myForm').focus();
});
</script>
</head>
<body>
<form name="myForm" id="myForm" method="post"></form>
</body>
</html>

Upvotes: 0

user3763367
user3763367

Reputation: 147

Try the below code -

$('<input/>').attr({ type: 'text', id: 'test', name: 'test', autofocus: 'true' }).appendTo('#form');

Upvotes: 0

Abhay Yadav
Abhay Yadav

Reputation: 23

try for focus

$('<input/>').attr({ type: 'text', id: 'test', name: 'test'}).appendTo('#form');

$('#test').focus(function(e) {
    alert('Focus');
});

Upvotes: 3

Related Questions