Category: Programming

All about programming

JQuery snippets

Author: | Categories: Programming No Comments
Adding text to a span using jquery $("#spanid").text("Your text here"); Adding html to a span using jquery $("#spanid").text("HTML here"); Append html to a span using jquery $("#spanid").append("HTML here"); Check/uncheck a checkbox input or radio button $("#x").prop("checked", true); $("#x").prop("checked", false); Check checkbox checked property $("#x").is(':checked') Handle change of checkbox $('#x').change(function() { if($(this).is(":checked")) { //'checked' event code […]

Javascript console messages

Author: | Categories: Programming No Comments
Most modern browsers include Developer tools which helps developers analyze client html and scripts. To write something from Javascript to console below options are available. Error gives you the red error message console.error(message); Default gives the default message console.log(message); Warning gives the warning message with the exclamation mark in front of it console.warn(message); Information gives […]

ASP.NET Send Canvas to Server as File Using Ajax

Author: | Categories: Programming No Comments
HTML 5 introduces canvas element as a resolution-dependent bitmap canvas which can be used for rendering graphs, game graphics, or other visual images on the fly. A canvas is a rectangle in your page where you can use JavaScript to draw anything you want. Below is the code save graphics drawn on Canvas to server […]

ASP.Net persist readonly textbox value on postback

Author: | Categories: Programming No Comments
As a security measure in the asp.net the readonly fields and disabled fields loose their values in postbacks. To retain the readonly textbox value after postback instead of making the textbox readonly using properties option, use attributes in code: TextBox1.Attributes.Add(“readonly”, “readonly”); that will still make the textbox readonly and will also retain the value after […]

ASP.NET calling Webmethod using jQuery

Author: | Categories: Programming No Comments
To call Webmethod asynchronously in ASP.net through jQuery Javascript Code <script type=”text/javascript”> function Authenticate() { $.ajax({ type: "POST", url: "/login.aspx/Authenticate", data: "{ provide json data }", contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { if (msg.d == '1') { alert(‘authenticated’); } else { alert("not authenticated"); } }, error: function() { alert("Error :("); } }); }; […]

Enable Pretty Permalinks on WordPress

Author: | Categories: Linux, Programming No Comments
Set pretty permalinks in Settings .htaccess file must look like this # BEGIN WordPress RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] # END WordPress Enable mod_rewrite on terminal window a2enmod rewrite Enable AllowOverride in Apache config file so that Apache reads .htaccess file <Directory […]

Check / Uncheck checkbox and radio button with jquery

Author: | Categories: Programming No Comments
You can check or uncheck a checkbox element or a radio button using the .prop() method // Check #x $( "#x" ).prop( "checked", true ); // Uncheck #x $( "#x" ).prop( "checked", false );

Parse Json data with JQuery

Author: | Categories: Programming No Comments
JavaScript has builtin functionality to read JSON objects. Let’s say there is a json like: [ { "id" : "1", "name" : "test1" }, { "id" : "2", "name" : "test2" }, { "id" : "3", "name" : "test3" }, { "id" : "4", "name" : "test4" }, { "id" : "5", "name" : "test5" […]