Archive for November, 2008

 

Reset form with jQuery (part II)

Here I noted how to reset a form with jQuery, however, later I noticed some fields aren’t reset() correctly: in my form I have hidden fields with initial value of “0″ (or just an empty value) and these fields are supposed to be changed interactively upon a user’s input using jQuery. These fields weren’t reset correctly for some reason, at least in Firefox, thus I had to change my original function to something like this:

1
2
3
4
5
function resetForm(id) {
	$('#' + id + ' :input').each(function(){  // I decided not to have different reset routine for different field types
			$(this).val('');
	});
}

Probably less elegant, but works… ;)

Last.fm scrobbler for Linux

Last.fm released scrobbler for Linux, before they offered to use Amarok, which wasn’t very convenient for me to use with their service of online listening to library/stations.

The scrobbler from their official site couldn’t be compiled (occasionally) but I found last.fm client in rpmfusion-free-updates yum repository (#yum install lastfm.i386).





How to .reset() form with jQuery

Such jQuery call won’t work:

1
2
	$('#formId').reset();
	// error: $("#formId").reset() is not a function

As the tutorial shows (yes, I never read manuals before I get into troubles as well, but always google answers before think, lol), we can have the following:

1
2
3
4
5
function resetForm(id) {
	$('#'+id).each(function(){
	        this.reset();
	});
}

…and somewhere on a page this:

1
	<input type="button" onclick="resetForm('formId');" />