Solution As we know a simple SQL select statement goes like this: select column_names from table_name Now, If we want to add a condition to selected records based on a single value of a column, we use where clause select column_names from table_name where column_value=value Example USE [DB_Name] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER... Continue Reading →
SQL stored procedure to delete a specific record based on id
Solution USE [DB_Name] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE [dbo].[sp_DeleteMember] @Id as bigint AS BEGIN SET NOCOUNT ON; Delete from Members_Table where ID = @Id END Explanation This delete stored procedure will delete the member from Members_Table whose member id is passed.
Get id of selected dropdown value in jquery
Solution var selectedid=$("#dropdownname").find('option:selected').attr('id'); Explanation This will find the id of selected dropdown option and store it in the variable selectedid.
Javascript function to calculate age from date of birth entered in a text box
Solution function calculateAge() { var dob = $('#DateOfBirth').val(); dob = new Date(dob); var today = new Date(); var age = Math.floor((today - dob) / (365.25 * 24 * 60 * 60 * 1000)); $('#Age').val(age); } Explanation dob will get the date of birth from DateOfBirth text box. It will convert it into date so to... Continue Reading →
Function to allow numbers only using Regex
Regex to allow numbers only Solution In JQuery var checkNumbers = function (textBox) { debugger; var regexp = new RegExp('^[0-9]+$'); var check = textBox.value; if (!regexp.test(check)) { alert('Invalid Value. Please enter numbers only'); $(textBox).css('border-color', 'red'); return false; } else { $(textBox).css('border-color', 'green'); $(textBox).value = check; return true; } } In HTML @Html.TextBox("AddAge", null, new {... Continue Reading →
Function to validate Date of Birth using Regex
Regex to validate date of birth Solution In Jquery var checkDOB = function () { debugger; var regexp = new RegExp( '^(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/](19|20)\\d\\d$'); var check = $("#AddDateOfBirth").val(); if (!regexp.test(check)) { alert('Invalid Format. Please Enter: dd/mm/yyyy'); $('#AddDateOfBirth').css('border-color', 'red'); return false; } else { $('#AddDateOfBirth').css('border-color', 'green'); return true; } } In HTML @Html.TextBox("AddDateOfBirth", null, new { @class =... Continue Reading →
Object Operators in PHP
Answer There are two object operators in PHP. The symbols are -> and :: -> Operator The object operator -> is used when you have to access an Instance property or call a method just like a dot (.) in other languages. For example, if there is a 'Students' class that includes the method 'Marks',... Continue Reading →
What is PSS of a process?
Answer The "proportional set size" or PSS of process is the sum of the unshared memory of a process and the proportion of memory shared with other processes. Formula: unshared memory of a process + (memory shared with other processes /number of processes that share memory) We'll understand through an example Example Process A has... Continue Reading →
Function to validate CNIC using Regex
Solution In JQuery var checkCNIC = function (textBox) { debugger; var regexp = new RegExp('^[0-9+]{5}-[0-9+]{7}-[0-9]{1}$'); var check = textBox.value; if (!regexp.test(check)) { alert('Invalid CNIC'); $(textBox).css('border-color', 'red'); return false; } else { $(textBox).css('border-color', 'green'); $(textBox).value = check; return true; } } In HTML @Html.TextBox("AddCNIC", null, new { @class = "form-control text-box", @placeholder = "11111-1111111-1", @onchange =... Continue Reading →
Validate form to check if any text box is empty on submit
Solution Call this function on submit or save button to validate the form. var checkEmpty = function () { var formInvalid = false; $('#MyForm').each(function () { if ($(this).val() === '') { formInvalid = true; } }); if (formInvalid) { alert('One or more fields are empty. Please fill up all fields'); return false; } else return... Continue Reading →