Friday, July 11, 2014

how to generate Serial numbers +Add 1 in select statement sql

SELECT ROW_NUMBER() OVER (ORDER BY ID) AS Id, Question FROM  RiskQuestion WHERE (UserID = " + userId + ")

Friday, July 4, 2014

Convert string to int using javascript

var noofQuestions = parseInt($('input[id$=hdfNoofQuestions]').val());

Add data index to section using javascript

 <section class="q-panel q-question q-question-transition" data-validation="radio"
                    id="mysec" data-name="response-to-loss" data-optional="false" style="left: -130%;">

 $(document).ready(function () {
            var s = 0;
            $('#mysec').attr('data-index', s);
        });

Thursday, July 3, 2014

Redirect webpage in JavaScript

window.location.href = "http://shekhar619.blogspot.in/";

Trim a String in JavaScript

Enter a string with spaces in front and back and press Trim String button<br> <br>
String: <input id="foo" type="text" value="   a quick brown fox jumps over  ">
<button onclick="trim()">Trim String</button>
<script>
if (!String.prototype.trim) {
   String.prototype.trim=function() {
    return this.replace(/^\s+|\s+$/g, '');
   };
}
function trim() {
    var foo = document.getElementById("foo").value;

    alert("(" + foo.trim() + ")");
}
</script>

javascript Function Remove Duplicates from JavaScript Array

function removeDuplicates(arr) {
    var temp = {};
    for (var i = 0; i < arr.length; i++)
        temp[arr[i]] = true;
 
    var r = [];
    for (var k in temp)
        r.push(k);
    return r;
}
 
//Usage
var fruits = ['apple', 'orange', 'peach', 'apple', 'strawberry', 'orange'];
var uniquefruits = removeDuplicates(fruits);
//print uniquefruits ['apple', 'orange', 'peach', 'strawberry'];

Check if String contains another substring in JavaScript

Enter two strings and check if Strign 1 contains String 2.<br> <br>
String 1: <input id="foo" type="text" value="a quick brown fox jumps over">     <br>
String 2: <input id="bar" type="text" value="fox jumps">    <br><br>
<button onclick="checkstring()">Click to check if String 1 contains String 2</button>
<script>
if (!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(obj, start) {
         for (var i = (start || 0), j = this.length; i < j; i++) {
             if (this[i] === obj) { return i; }
         }
         return -1;
    }
}

if (!String.prototype.contains) {
    String.prototype.contains = function (arg) {
        return !!~this.indexOf(arg);
    };
}

function checkstring() {
    var foo = document.getElementById("foo").value;
    var bar = document.getElementById("bar").value;

    alert(foo.contains(bar));
}
</script>