Focus on first input text in jQuery

Categories: Development, Tips, code



I’m doing a little bit of polishing while finishing up some forms. I got this fade-in effect and wants to get the first input text to be focused when the animation ends.

function show_form(formname)
{
    hide_all();
	$('#' + formname).css('opacity', 0).parent().show();
    $('#' + formname).animate({opacity: 1}, 'normal', function(){

		// focus on the first input in the form
		$('#'+formname+' input:text:first').focus();

		offset = $('#add_new').offset().top;
		$('html, body').animate({
                 scrollTop: offset }, 2000);
	});

    return false;
}

 There’s an additional effect in that function. It’ll scroll down to the form because there’s a list above the form, so, it’ll just scroll right pass it.

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.