How to get the value of a selected radio button using its name in jQuery?

hello guys,

here is simple code for how to get selected radio button using its name in jquery.

$('input:radio[name=theme]:checked').val();

dat’s it.!!

Advertisements

Dealing with bootstrap alert

hello guys,

I got some problem while dealing with bootstrap alert.

How to show bootstrap alert div again

when we close alert div box, then if again we can’t show that div box. even if we write jquery show() function.

solution:

checkout  <a> tag there you got data-dismiss=”alert” , this will remove div from dom so that’s why we can’t show that div again. so just remove that and bind your function to that div

code:

<a id=”lieclose” onclick=”general_close(this.id)”>×</a>

jquery code:

function general_close(id)
{
	var current_id = "#"+id;
	$(current_id).parent().hide();
}

above function will work for any alert div. just change your id in a tag.

How to redraw bootstrap-error message

$('#loginerrbox').empty();
$('#loginerrbox').append("Please enter valid credentials. 
<a id='crdlogerr' class='close' onclick='general_close(this.id)'>×</a>");					
$('#loginerrbox').show();

above code demonstrate how to redraw new error message on alert div.

hope you like above Tips 🙂

jquery datatable simple n effective example

hello guys,

let’s go for very simple DataTables example which is filled by jquery ajax call.

Import bellow file in your html heading section

!!! note :–  just replace &gt; with > (end tag)

<link rel=”stylesheet” type=”text/css” href=”http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/css/jquery.dataTables_themeroller.css”&gt;
<link rel=”stylesheet” type=”text/css” href=”http://datatables.net/media/blog/beautiful_tables/complete.css”&gt;
<script type=”text/javascript” charset=”utf8″ src=”http://ajax.aspnetcdn.com/ajax/jquery.dataTables/1.9.4/jquery.dataTables.min.js”&gt;
</script>

JQuery function

$.ajax({
        	type: "GET",
		data: {data: pass ur data},
           	url:  "give your php file url here",
            	contentType: "application/json; charset=utf-8",
            	success: function(data) {
		$('#table').append("<tr><td>YOUR DATA HERE</td></tr>"); 
                $('#table').dataTable({
                   "sScrollY": 200,
                   "bJQueryUI": true,
               }); 
            } 
 });

HTML code for table

<table cellpadding=”0″ cellspacing=”0″ border=”0″ id=”ausgroup” width=”80%”>
<thead>
<tr>
<th>Your Heading </th>
</tr>
</thead>
<tbody>
</tbody>
</table>

Note

some important option listed bellow

“bJQueryUI”: true,       — for UI css of Table
“bPaginate”: false,        — for Pagination
“bLengthChange”: false,
“bFilter”: true,                — for filter
“bSort”: true,                 — for sorting

Redraw Datatable with fresh data

     $.ajax({
	            type: "GET",
	            url: "your url",
        	    success: function(data) {
		       if (typeof oTablelb != 'undefined') 
		        oTablelb.fnClearTable();
		        $('#lbtable').append("<tr><td>your data</td></tr>"); 
                        oTablelb=$('#lbtable').dataTable({ 
                                  "bDestroy": true, 
                                  "sScrollY": 200, 
                                  "sScrollX":400, 
                                  "bJQueryUI": true, 
                               }); 
                    } 
        });

just set bellow property

1) if (typeof oTablelb != 'undefined') oTablelb.fnClearTable();

2) "bDestroy": true,

now run your file,  DataTable will reload fresh data based on ajax call.  🙂

hope you like it!!