Javascript for beginners



if you want to access the content of a any control. we can use this code.


Code Snippet


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

                function Validation() 
                       
 { 
                         
    var txtFirstName = document.getElementById ("txtFirstName").value;


                           alert(txtFirstName ); 

// Display the text which was entered in the given textbox
                        } 
  
</script> 
 

How tocall this function in button click

 <asp:buttonID="btnSubmit" runat="server" OnClientClick=" validate();"
                       />


onClick and OnClientClick

Here we use OnClientClick for validation purpose and for doing process on server side, we are using onClick.OnClientClick always goes first since it happens on client side, OnClick happens on the server where the page arrives after a postback.

Email Validation


 var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
 var txtEmail= document.getElementById ("txtEmail").value;

            if (reg.test(txtEmail) == false) 
{
                alert('Invalid Email Address');
            }
               

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: