Reputation: 63
...
$(document).ready(function(){
$('form').submit(function(){
$('input#second').focus();
return false;
});
$('#first').blur(function(){
alert('blur');
});
});
...
<form>
<input id=first><br>
<input id=second><br>
<input type=submit>
</form>
...
Then the following happens:
Here is a live demo.
What am I missing?
Thanks
Upvotes: 2
Views: 829
Reputation: 63
According to this comment over at JQuert bugtracker, the work around the problem is to use
$('input#second')[0].focus();
instead of
$('input#second').focus();
Whether it is a bug is still to be decided by jq people in charge, but I would guess that it is because
Thanks, everyone. Night.
Upvotes: 1
Reputation: 86892
Nick is right your HTML is really messed up. You have not ended you input tags or the br(s). On top of that you should put your attribute values in your input tags in double quotes.
This works here is a demo http://www.jsfiddle.net/dAdG8/
<script type="text/javascript">
$(document).ready(function(){
$('form').submit(function(){
$('input#second').focus();
return false;
});
$('#first').blur(function(){
alert('blur');
});
// logging
$('input').blur(function(){
$('pre').append('blur, ' + this.id + '\n');
});
$('input').focus(function(){
$('pre').append('focus, ' + this.id + '\n');
});
});
</script>
<form>
<input id="first" />
<br />
<input id="second" />
<br />
<input type="submit" />
</form>
Upvotes: 2