Convert all checked checkboxes into an comma seperated string with JQuery

Sometimes i just love jQuery. Well most of the time actually. I did some work for a client a couple of week ago and i needed get all checkoboxes that was checked as a comma seperated list. I started with this code. I found out about the “map” method of jQuery wich has the following description.

Translate all items in an array to another array of items.

The translation function that is provided to this method is called for each item in the array and is passed two arguments: The the item to be translated, and index within the array.The function can then return the translated value, ‘null’ (to remove the item), or an array of values – which will be flattened into the full array.

The code i ended up with looked like this. Really really neat.

Publicerat av den

Using JQuery Validation plugin with ASP.NET

Like everyone else i’ve been playing around with JQuery a lot lately. and JQuery is not the best friends in the world but i guess it will be a lot better when using ASP.NET MVC. Microsoft also announced that they will support JQuery natively in future versions. Nice!

If you want to learn more about ASP.NET and Jquery be sure to read both Rick Sthral’s and the Encosia blogs.

I’m working on a new project now where i am trying to stay away from ajax mainly because of performance reasons but also just because i want to learn something new. Today i’ve been using the JQuery Validation plugin.

There is alot of documentation of how to use it on the the documentation pages for the plugin but i want to share with you one thing that i had problems with.

This is some regular example code that all the sample’s use. The problem here is that for example “EmailTextbox” is not the ID of the control but the name.

I scratched my head for a long long time when i used ctl00_ContentPlaceHolder1_EmailTextbox and nothing worked at all. So what you have to do is change this to something like this ..

You could of course also use some method that rewrite the Control.UniqueID to a name and use <%= %> to get the name of the control.

Publicerat av den