Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Friday, 31 August 2012

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute 
                           '{ "@id": 1001, "@name": "Sony", "edu": "MCA" }'
Usually we do use alert(data.edu); to get the values but when @ is with attribute then use the bellow code

 var attName = data['@id'];
 alert(attName);

      or

 var att = '@name';
 var attID = data[att];

 alert(data.edu);




Tags: @ in json, @ symbol in json response, Parsing JSON with @ symbol in it.

Thursday, 15 March 2012

Allow only numbers in textbox using javascript

Use the following code:

function AllowNumsOnly(evt)
{
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        document.getElementById('spnError').innerHTML = 'Allows only numbers';
        return false;
    }
    else {
        document.getElementById('spnError').innerHTML = '';
        return true;
    }
}
<style>
    #spnError {color:Red;font-size:11px;}
</style>
<asp:TextBox ID="txt_Qty" runat="server" onkeypress="return AllowNumsOnly(event);"></asp:TextBox><span id="spnError"></span>

Tag: Allow only numbers in textbox using javascript,allow numbers only onkeypress

Monday, 5 March 2012

How to create remember me Cookie in javascript


Creating cookie when user submits the Login page with proper credentials


if(UserCredentilas correct)

{

HttpCookie aCookie = new HttpCookie("UserInfo");

aCookie.Values["uname"] = Request.Form["txtEmail"].ToString();

aCookie.Values["pwd"] = Request.Form["txtPassword"].ToString();

if (Request.Form["chk_RememberMe"] != null)

aCookie.Expires = DateTime.Now.AddYears(50);

else

aCookie.Expires = DateTime.Now.AddDays(0);

Response.Cookies.Add(aCookie);

}


Use the following code in javascript of LoginPage


<body onload="javascript:getCookie('UserInfo');"></body>

<script language="javascript" type="text/javascript">

    function getCookie(c_name)

    {

        var i,CooP,ARRcookies=document.cookie.split(";");

        for (i=0;i<ARRcookies.length;i++)

        {

            CooP=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));

            var CooPar=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);

            CooP=CooP.replace(/^\s+|\s+$/g,"");

            if (CooP==c_name)

            {

                var CooParList=CooPar.split("&");

                var CooCList=CooParList[0].split("=");

                document.getElementById('txt_Username').value=CooCList[1];

                CooCList=CooParList[1].split("=");

                document.getElementById('txt_Password').value=CooCList[1];

                document.getElementById('chk_Rememberme').checked=true;

            }

        }

    }

</script>


Tag: remember me code in javascript, remember me code in asp.net, remember me code in asp.net c#, remember me code in php, remember me code in java, remember me asp.net login control

Tuesday, 28 February 2012

input text box watermark effect using jquery


<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js" type="text/javascript"></script>
<style type="text/css">
.UsernameCss { color:#9B9B9B; }
</style>

$("txtUserName").addClass("UsernameCss").val("Username")
.focus(function(){ if($(this).val() == "Username") { $(this).removeClass("UsernameCss").val(""); } })
.blur(function(){ if($(this).val() == "") { $(this).val("Search").addClass("UsernameCss"); } });

<input id="txtUserName" name="txtUserName" type="text" />


Tag: css, input, jquery, jquery watermark for textbox, textbox, watermark

Tuesday, 21 February 2012

Share on Facebook and Twitter


Sharing your web page on Facebook and Twitter code follows:



<a href="http://www.facebook.com/share.php?u=<;url>" onclick="return fbs_click()"><img src="images/fshare.png" title="Share To Facebbok" alt="Share To Facebbok" width="84" height="29" /></a>


<a id="aTweet" href="https://twitter.com/share" data-count="none" onclick="return Tweet_click()"><img src="images/retweet.png" title="Tweet" alt="Tweet" width="29" height="29"/></a>



<script type="text/javascript">

function fbs_click()

{

    u = location.href;

    t = document.title; window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');

    return false;

}

function Tweet_click() {

    u = location.href;

    t = document.title; window.open('https://twitter.com/share?url=' + encodeURIComponent(u) + '&amp;via=' + encodeURIComponent(t), 'sharer','toolbar=0,status=0,width=626,height=436');

    return false;

}

</script>



Tag: button, facebook share, fb share, fbs_click(), share, share on facebook, Tweet_click(), twitter share



Wednesday, 1 February 2012

Closing new tab using javascript

Use this code
<script type="text/javascript"> function close_new_tab() {close();} </script>
<input type="button" name="" onclick="javascript:close_new_tab();return false;" value="Close" title="Close" />

Tag: Close, closing, input, javascript, new, tab, using, window

Monday, 5 December 2011

Disabling Right-Click on a web page


To protect your source code should not be copied either by using right click or by ctrl+c then use the bellow code in head tags

<head>
 <title>Untitled Page</title>
 <meta http-equiv="imagetoolbar" content="no" />
 <script type="text/javascript" language="javascript">
  var msg="Sorry, right-click has been disabled";
  function WhenIE() {if (document.all) {alert(msg);return false;}}
  function WhenNS(e) {if
   (document.layers||(document.getElementById&&!document.all)) {
    if (e.which==2||e.which==3) {alert(msg);return false;}}}
   if (document.layers)
    {document.captureEvents(Event.MOUSEDOWN);document.onmousedown=WhenNS;}
   else{document.onmouseup=clickNS;document.oncontextmenu=WhenIE;}
    document.oncontextmenu=new Function("return false")
 </script>
 <script type="text/javascript" language="javascript">
 function disableselect(e){ return false }
 function reEnable(){ return true }
 document.onselectstart=new Function ("return false")
 if (window.sidebar){
  document.onmousedown=disableselect
  document.onclick=reEnable
 }
</script>
</head>

Tag: asp, Click, content, Disabling, dot, double, image, java script, net, protect, Right, save, secure, selection text, source code, web page

Monday, 14 November 2011

ASP.NET authentication login and logout with browser back button

ASP.NET authentication login and logout with browser back button

private void Page_Load(object sender, System.EventArgs e)
{  
     // Put user code to initialize the page here
     Session.Abandon();
     FormsAuthentication.SignOut();
}
              OR
private void Page_Load(object sender, System.EventArgs e)
{
     Session.Abandon();
     Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1));
     Response.Cache.SetCacheability(HttpCacheability.NoCache);
     Response.Cache.SetNoStore();
}


Tag: Asp.net, browser back button, login, logout

Monday, 10 October 2011

Changing title in javascript

<head>
<title>Original Title</title>
</head>
<body>
<form id="frm">
<div>
<input type="button" onclick="javascript:document.title='My New title';" value="Change title" />
</div>
</form>
</body>
</html>


Tag: Asp.net, calling server method from javascript, document.title, dynamic title in html, title

Get Url Parameters using Javascript

            Nearly all server-side programming languages have built-in functions to retrieve querystring values of an URL. In web browsers you can access the querystring with client-side JavaScript, but there is no standard way to parse out the name/value pairs. So here is a function to return a parameter you specify. The following javascript code snippet facilitates Javascript's built in regular expressions to retrieve value of the key. Optionally, you can specify a default value to return when key does not exist.

<script language="javascript" type="text/javascript">
    function getParamValue(key, default_)
    {
        if (default_==null) default_="";
            key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
        var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
        var qs = regex.exec(window.location.href);
        if(qs == null)
            return default_;
        else
            return qs[1];
    }
    function GetUrl()
    {
        var a=getParamValue('a',' ');
        var b=getParamValue('b',' ');
        if(a!=' ' && b!=' ')
            alert("a: "+a+";  b: "+b);
    }
    </script>
</head>
<body onload="GetUrl();">
<body>

Tag: javascript, javascript function, query string, querysting in javascript, url parameters

Thursday, 15 September 2011

Opening a Popup window in asp.net and process it and then refreshing the parent window by closing child window using javascript in asp.net


Parent p.aspx page aspx code:

<script language="javascript" type="text/javascript">
function divert(pkvalue)
{
    var strUrl = "c.aspx?pkvalue="+pkvalue;
    window.open(strUrl, '', 'status=1,scrollbars=1,width=280,height=180');
}
function CallParentFunction()
{

   //window.location.href ="p.aspx";
   window.location.reload();    //Anything will work

}
</script>

<body><form id="form1" runat="server"><div>
<a id="edit1" onclick="javascript:divert(this.id);">Edit1</a>
</div></form></body>

Child c.aspx page aspx.cs code:
protected void Page_Load(object sender, EventArgs e)
{
    string s= Request.QueryString["pkvalue"].ToString();
    lblmsg.Text = "pkvalue:" + s;
    //var s having pkvalue so you can show what to update
}
protected void btnSave_Click(object sender, EventArgs e)
{
    //process saving your data
    ScriptManager.RegisterStartupScript(this, this.GetType(), "calling parent", "javascript:window.close();", true);
}


Child c.aspx page aspx code:
<body onunload="window.opener.CallParentFunction();">
<form id="form1" runat="server">
<div>
<asp:Label ID="lblmsg" runat="server" ></asp:Label>
<br /><asp:Button ID="btnSave" runat="server" Text="Save & Close" onclick="btnSave_Click" />
</div>
</form>
</body>

Tag: Opening a Popup using javscript, Opening a Popup window in asp.net, Refreshing parent window in asp.net, Refreshing parent window in asp.net using javascript, Refreshing parent window using Javascript

Friday, 9 September 2011

how to add icon in browser tabs

Add this below line of code
<link rel="shortcut icon" type="image/ico" href="your_image.ico" />
in the the header section..


Tag: how to add icon in browser, how to add icon in browser tabs, how to add icon in browser tabs asp.net, how to add icon in browser tabs in .net, how to add icon in browser tabs in asp.net

Friday, 26 August 2011

Vowels count in javascript


<script language="javascript" type="text/javascript">
    function check()
    {
        var str =document.getElementById("textboxing").value;
        var chr = ""
        var nVowels = 0
        //Counting all the vowels except y.
        for (pos = 0; pos < str.length; pos++)
        {
            chr = str.charAt(pos);
            if (chr == "a" || chr == "e" || chr == "i" || chr == "o" || chr == "u" ||
                chr == "A" || chr == "E" || chr == "I" || chr == "O" || chr == "U")
                nVowels++;
        }
            alert("There were " + nVowels + " vowels.");
    }
    </script>


<input type="text" id="textboxing" />
    <input type="button" onclick="check()" />


i/p :  india  --- o/p : There were 3 vowels
i/p :  bDf   --- 0/p : There were 0 vowels

Tag: vowel count in string in javascript, vowels count in javascript, vowels count in javascript in asp.net

Monday, 8 August 2011

Getting the List of Latitude and Longitude based on GeoCoordinates with in a radius

CREATE function [dbo].[udf_Haversine](@lat1 float, @long1 float,@lat2 float,@long2 float)returns float
begin
declare @dlon float, @dlat float, @rlat1 float,@rlat2 float, @rlong1 float, @rlong2 float,
@a float, @c float, @R float, @d float, @DtoR float
select @DtoR = 0.017453293
select @R=6371 --6371 in km & 3959 in miles ::Earth radius::
select @rlat1 = @lat1 * @DtoR,@rlong1 = @long1 * @DtoR,@rlat2 = @lat2 * @DtoR,@rlong2 = @long2 * @DtoR
select @dlon = @rlong1 - @rlong2,@dlat = @rlat1 - @rlat2
select @a = power(sin(@dlat/2), 2) + cos(@rlat1) * cos(@rlat2) * power(sin(@dlon/2), 2)
select @c = 2 * atn2(sqrt(@a), sqrt(1-@a))
select @d = @R * @c
return @d
end

CREATE PROCEDURE Search_GeoCoordinates(@latitude float,@longitude float,@radius_kms float)
AS
BEGIN
SET NOCOUNT ON;
Begin
select id,houseaddr,latitude,longitude from tbl_house
where dbo.udf_Haversine(CONVERT(Float,ISNULL(latitude,0.00)),CONVERT(Float,ISNULL(longitude,0.00)),@latitude,@longitude)<@radius_kms
End
END

Tag: Latitude,Longitude,Radius,asp.net

Thursday, 30 June 2011

How to use session variables in javascript function of .aspx page

<head runat="server">
    <title>Payment Page</title>
    <script language="javascript" type="text/javascript">

     function checkSession()
    {
        var cid='<% =Session["CustomerId"] %>';
        if(cid!=null && cid!="")
        {
            return true;
        }
        else
        {
            alert("your session is expired plz login");
            return false;
        }
    }
    </script>
</head>
<asp:Button ID="btnSave" runat="server" Text="Save" OnClientClick="javascript:return checkSession();" OnClick="btnSave_Click" />

tag: session variable in javascript fuction in asp.net, Using of Session Variable in asp.net

Parsing JSON w/ @ symbol in it

To read the json response like bellow @ concatenated with attribute                             '{ "@id": 1001, "@name...