Thursday 20 October 2011

Accept only a number in a textbox using through java script

Follow these steps:-

1) Allowing only certain character in a text box.
2) Validation in TextBox which accepts only numbers value.
3) Allow only numbers / digits in TextBox.

Here is the code bellow
for the text box where digits are allowed and alphabetic characters are not allowed. Observe, too, that arrow keys and backspace _are_ allowed so that you can still edit what you type.


Just copy and paste java script code inside <head> tag and call the java script function on text box onkeypress event as given bellow.

Here is the two example you can try any of them all are working fine in all browsers IE and Netscape/Mozilla.
<script type="text/javascript">
            function fnAllowNumeric() {
                  if ((event.keyCode < 48 || event.keyCode > 57) && event.keyCode != 8) {
                         event.keyCode = 0;
                         alert("Accept only Integer..!");
                         return false;
                     }
                }
</script>

<BODY>
    <INPUT id="txtChar" onkeypress="return fnAllowNumeric()"type="text"/>
</BODY>



Second:-

<script type="text/javascript">
       function CheckNumericValue(e) {

        var key;
        key = e.which ? e.which : e.keyCode;

        //enter key  //backspace //tabkey      //escape key                   
        if ((key >= 48 && key <= 57) || key == 13 || key == 8 || key == 9 ||             key == 27) {
            return true;
            }
        else
           {
            alert("Please Enter Number Only");
            return false;
           }

      }
</script>

<BODY>
  <INPUT id="txtChar" onkeypress="return CheckNumericValue(event)"type="text"/>
</BODY>

Update a table with another table's data with a conditions in sql server


Update a table with another table's data with a conditions in sql server


This is the example to update table from another table where Empid is same and according some conditions.

We have to update 'tblEmpdetails' table
'Acno' as mention on second table 'tblEmpAcNo' with the condition that department must be 'Hr', Both table given bellow and updating query also given bellow.

Table 1 :- tblEmpDetails  
EmpIdageDepAcno
E120IT09876565
E230Hr75445678
E331Hr45674570
Table2 :- tblEmpAcNo 
EmpIdAcno
E102537565
E285245678
E341546456
E434074570
E545379200


UPDATE tblEmpDetails SET tblEmpDetails.AcNo = tblEmpAcNo.AcNo
FROM tblEmpAcNo
WHERE tblEmpDetails.EmpId = tblEmpAcNo.EmpId
AND tblEmpDetails.Dept = 'Hr'
GO

Wednesday 19 October 2011

A stylish hower menu using AJAX Hower Demonstration

Css of hower menu:-


<style type="text/css">
                            .popUpContent
                            {
                                background-image: url("image path");
                                background-repeat: repeat-y;
                                margin-bottom: 0;
                                margin-left: 0;
                                margin-right: 0;
                                margin-top: 0;
                                padding-bottom: 10px;
                                padding-left: 10px;
                                padding-right: 10px;
                                padding-top: 5px;
                                top: -1px;
                                width: 593px;
                            }
                            .popUpTop
                            {
                                background-image: url("image path");
                                background-repeat: no-repeat;
                                height: 44px;
                                margin-bottom: 0;
                                margin-left: 0;
                                margin-right: 0;
                                margin-top: 0;
                                padding-bottom: 0;
                                padding-left: 0;
                                padding-right: 0;
                                padding-top: 0;
                                width: 593px;
                            }
                            .popUpBottom
                            {
                                background-image: url("image path");
                                background-repeat: no-repeat;
                                height: 18px;
                                margin-bottom: 0;
                                margin-left: 0;
                                margin-right: 0;
                                margin-top: 0;
                                padding-bottom: 0;
                                padding-left: 0;
                                padding-right: 0;
                                padding-top: 0;
                                top: -1px;
                                width: 593px;
                            }
                            .popUpText
                            {
                                padding-bottom: 0;
                                padding-left: 40px;
                                padding-right: 20px;
                                padding-top: 0;
                            }
                            .popUpHeading
                            {
                                color: #E97714;
                                font-weight: bold;
                                padding-bottom: 0;
                                padding-left: 50px;
                                padding-right: 15px;
                                padding-top: 20px;
                            }
                            .popUp
                            {
                                line-height: 1.6em;
                                position: absolute;
                                width: 593px;
                                z-index: 1000;
                                left: 130px;
                                top: -38px;
                            }
                            .PopUpCont
                            {
                                position: absolute;
                                top: -9999999999;
                                left: -99999999;
                            }
                            .menuleft a
                            {
                                font-family: Arial;
                                text-decoration: none;
                                font-size: small;
                                text-transform: capitalize;
                                background-image: url("image path");
                                background-repeat: no-repeat;
                                color: #000080;
                                display: block;
                                font-size: 13px;
                                height: 26px;
                                padding-bottom: 0;
                                padding-left: 10px;
                                padding-right: 0;
                                padding-top: 8px;
                                width: 168px;
                            }
                        </style>



Code of Java Script:-


<script type="text/javascript">
                            var myTitle = ""
                            var myContent = ""

                            function getContentText(id) {

                                switch (id) {
                                    case 1:
                                        myTitle = "Save money and staff"
                                        myContent = " Saving money by outsourcing makes sense.</br> But it usually fells behind more strategic motives.</br> Such as focusing on core business or freeing up internal staff for other initiatives.</br>  Given the current economic situation more and more companies consider outsourcing.</br> Thus reduce IT costs and being more flexible in the market.</br> Last, but not least, no trouble with employees."
                                        break;

                                    case 2:
                                        myTitle = "ICC flexibility"
                                        myContent = "ICC is a flexible, experienced, reliable IT outsourcing and consultancy partner.</br> Escalate your business to a higher level, while retaining quality and productivity."
                                        break;

                                    case 3:
                                        myTitle = "Expertise on demand"
                                        myContent = "From one minute to the another, you have plenty of hands on board for your software projects.</br> ICC guarantees the highest quality in development, project management and technological innovation."
                                        break;


                                    case 4:
                                        myTitle = "Advertising agencies"
                                        myContent = "ICC is a trusted technology partner to advertising agencies.</br> More and more companies require smart solutions for their online campaigns. </br>  You focus on the art of communication.</br> Maxland IT on the art of bits and bytes."
                                        break;

                                    case 5:
                                        myTitle = "IT companies"
                                        myContent = "ICC offers the perfect opportunity for IT companies,</br> that are in need to free up hours by outsourcing tiresome work. Your employees will devote full attention to your esteemed customers.</br> This better service to your customers directly results in more projects for your IT business."
                                        break;

                                    default:
                                        myTitle = ""
                                        myContent = ""
                                }

                            }

                            function writePopup(id) {
                                getContentText(id);
                                var divid = "divPopup" + id.toString();
                                var myDiv = document.getElementById(divid);
                                var content = "";
                                content = content + "<div class='popUpTop'><div class='popUpHeading'>" + myTitle + "<hr /> </div>";
                                content = content + "</div>";
                                content = content + "<div class='popUpContent'><div class='popUpText'>";
                                content = content + myContent;
                                content = content + "</div></div>";
                                content = content + "<div class='popUpBottom'></div>";
                                myDiv.innerHTML = content;
                                leftContentPopupShow(divid);
                            }

                            function HidePopup(id) {
                                var divid = "divPopup" + id.toString();
                                var myDiv = document.getElementById(divid);
                                myDiv.innerHTML = "";
                                leftContentPopupHide(divid);
                            }


                            function leftContentPopupShow(p) {
                                document.getElementById(p).style.display = 'block';
                                //            document.getElementById("centerpage").setAttribute("class", "centerpage2")

                            }
                            function leftContentPopupHide(p) {
                                document.getElementById(p).style.display = 'none';
                                // document.getElementById("centerpage").setAttribute("class", "centerpage")

                            }
                        </script>

Call on div where ever u waana call javascript:-



           <div class="menuleft" style="width: 170px">
                            <ul style="list-style: none; padding-left: 0px; margin-left: 5px">
                                <li onmouseover="writePopup(1)" onmouseout="HidePopup(1)"><a href="#">Save money and
                                    staff</a>
                                    <div class="PopUpCont">
                                        <div id="divPopup1" class="popUp">
                                        </div>
                                    </div>
                                </li>
                                <li onmouseover="writePopup(2)" onmouseout="HidePopup(2)"><a href="#">Maximum flexibility</a>
                                    <div class="PopUpCont">
                                        <div id="divPopup2" class="popUp">
                                        </div>
                                    </div>
                                </li>
                                <li onmouseover="writePopup(3)" onmouseout="HidePopup(3)"><a href="#">Expertise on demand</a>
                                    <div class="PopUpCont">
                                        <div id="divPopup3" class="popUp">
                                        </div>
                                    </div>
                                </li>
                                <li onmouseover="writePopup(4)" onmouseout="HidePopup(4)"><a href="#">Advertising agencies</a>
                                    <div class="PopUpCont">
                                        <div id="divPopup4" class="popUp">
                                        </div>
                                    </div>
                                </li>
                                <li onmouseover="writePopup(5)" onmouseout="HidePopup(5)"><a href="#">IT companies</a>
                                    <div class="PopUpCont">
                                        <div id="divPopup5" class="popUp">
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>



Monday 17 October 2011

Restrict user to enter only number using javascript

Code:-



<script type="text/javascript">
//Function to allow only numbers to textbox
function validate(key)
{
//getting key code of pressed key
var keycode = (key.which) ? key.which : key.keyCode;
var phn = document.getElementById('txtPhn');
//comparing pressed keycodes
if ((keycode < 48 || keycode > 57))
{
return false;
}
else
{
//Condition to check textbox contains ten numbers or not
if (phn.value.length <10)
{
return true;
}
else
{
return false;
}
}
}
</script>

<asp:TextBox ID="txtPhn" runat="server" onkeypress="return validate(event)"></asp:TextBox>

Unrecognized escape sequence (error CS1009)

Unrecognized escape sequence :-

A common case for this error is using the backslash character in a file name. Replace “\” with “\\” or use “@” prefix for the literal as shown below.

Sunday 16 October 2011

Create stylish menu with css

Biscuit type menu through css:-

The HTML




<div id="nav-wrapper">
  <ul id="nav">
    <li><a href="">Home</a></li>
    <li><a href="">About</a></li>
    <li><a href="">Services</a></li>
    <li><a href="">FAQ</a></li>
    <li><a href="">Contact</a></li>
  </ul>
</div>

The CSS

#nav-wrapper {
width:465px;
margin:0 auto;
padding:20px 0;
background:#3D3331;
}
ul#nav {
font-family: Verdana;
font-size:14px;
list-style:none;
margin:0 auto;
padding:0;
width:455px;
overflow: auto;
}
ul#nav li {
display:inline;
}
ul#nav li a {
text-decoration:none;
display: block;
padding:5px 21px;
background:#5F3222;
color:#eee;
float:left;
text-align:center;
border-top:2px solid #815444;
border-right:2px solid #3d1000;
border-bottom:2px solid #3d1000;
border-left:2px solid #815444;
}
ul#nav li a:hover {
background:#a37666;
color:#000;
border-top:2px solid #815444;
border-right:2px solid #c59888;
border-bottom:2px solid #c59888;
border-left:2px solid #815444;
}