Sunday, December 9, 2012

Check if Checkbox is checked using jQuery


to find out if checkbox is checked or not using jQuery. I was knowing one way to find out but there are couple of other ways as well to find out if checkbox is checked using jQuery. In this post, you will find all different possible ways.

1. First Way:

Below single line of code will provide the status of checkbox using jQuery. It checks whether the checked is checked or not using jQuery and will return 1 or 0.

1var isChecked = $('#chkSelect').attr('checked')?true:false;
I have noticed that on many website it is written that 'checked' attribute will return true or false, but this is not correct. If the checked box is checked then it return status as "checked", otherwise "undefined".

2. Second Way
1var isChecked = $('#chkSelect:checked').val()?true:false;

3. Third Way
1var isChecked = $('#chkSelect').is(':checked');
The above method uses "is" selector and it returns true and false based on checkbox status.

4. Fourth Way

The below code is to find out all the checkbox checked through out the page.
1$("input[type='checkbox']:checked").each(
2    function() {
3       // Your code goes here...
4    }
5);
Feel free to contact me for any help related to jQuery, I will gladly help you.

Find Current Location of Data and Log File of All the Database and get size of databases

Some time for carring data from one machine to another machine we need to copy database file

for that we need to copy database ldf and mdf file becaues this is eassiest way yo carring database. for this  we must be know the these db files are where is located on server so we can copy this.

First way to write this query on our Query window

SELECT name, physical_name AS current_file_location
FROM sys.master_files

Second way to find the location with Appropriate database file size 

SELECT DB_NAME(mf.database_id) AS databaseName
,mf.physical_name
,num_of_reads
,num_of_bytes_read
,io_stall_read_ms
,num_of_writes
,num_of_bytes_written
,io_stall_write_ms
,io_stall
,size_on_disk_bytes
FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS divfs
JOIN sys.master_files AS mf ON mf.database_id = divfs.database_id
AND mf.file_id = divfs.file_id
ORDER BY 3 DESC 

Third way to find database details with size in shortest form that you wanted to find

SELECT
DB_NAME(mf.database_id) AS databaseName,
name as File_LogicalName,
case
when type_desc = 'LOG' then 'Log File'
when type_desc = 'ROWS' then 'Data File'
Else type_desc
end as File_type_desc
,mf.physical_name
,num_of_reads
,num_of_bytes_read
,io_stall_read_ms
,num_of_writes
,num_of_bytes_written
,io_stall_write_ms
,io_stall
,size_on_disk_bytes
,size_on_disk_bytes/ 1024 as size_on_disk_KB
,size_on_disk_bytes/ 1024 / 1024 as size_on_disk_MB
,size_on_disk_bytes/ 1024 / 1024 / 1024 as size_on_disk_GB

FROM sys.dm_io_virtual_file_stats(NULL, NULL) AS divfs
JOIN sys.master_files AS mf ON mf.database_id = divfs.database_id
AND mf.file_id = divfs.file_id
ORDER BY num_of_Reads DESC