• Home
  • Trace mobile number (From India)
  • Entertainment
  • SiteMap
  • Home
  • ASP.NET
  • C#
  • BLOGGING
  • SQL SERVER
  • FACEBOOK
  • Entertainment
Showing posts with label Javascript. Show all posts

The Geolocation API provides a method to locate the user’s exact  position. This is useful in a number of ways ranging from providing a user with location specific information to providing route navigation.Internet Explorer 9, Firefox, Chrome, Safari and Opera support Geolocation.

A number of different sources are used to attempt to obtain the user’s location, and each has their own varying degree of accuracy. A desktop browser is likely to use WiFi (accurate to 20m) or IP Geolocation which is only accurate to the city level and can provide false positives. Mobile devices tend to use triangulation techniques such as GPS (accurate to 10m and only works outside), WiFi and GSM/CDMA cell IDs (accurate to 1000m).

Use the getCurrentPosition() method to get the user's position.

The example below is a simple Geolocation example returning the latitude and longitude of the user's position:


<script>

var MyLoc=document.getElementById("demo");

function getUserLocation()

  {

  if (navigator.geolocation) //This will check if browser support geolocation.
   {
    navigator.geolocation.getCurrentPosition(showPosition);
   }
  else
  {
  MyLoc.innerHTML="Geolocation is not supported by this browser.";
  }
 
  }

  function showPosition(position)
  {
  MyLoc.innerHTML="Latitude: " + position.coords.latitude +
  "<br>Longitude: " + position.coords.longitude;
  }
</script>



The above function first Check if Geolocation is supported by browser If supported, run the getCurrentPosition() method. If Geolocation is supported by browser, display a message to the user .If the getCurrentPosition() method is successful, it returns a coordinates object to the function specified in the parameter ( showPosition ) and The showPosition() function gets the displays the Latitude and Longitude.

Displaying the Result in a Map

To display the result in a map, you need access to a map service that can use latitude and longitude, like Google Maps. Change the showPosition method like this .



<script>

var MyLoc=document.getElementById("demo");

function getUserLocation()

  {

  if (navigator.geolocation) //This will check if browser support geolocation.
   {
    navigator.geolocation.getCurrentPosition(showPosition);
   }
  else
  {
  MyLoc.innerHTML="Geolocation is not supported by this browser.";
  }
 
  }


function showPosition(position)

{

var latlon=position.coords.latitude+","+position.coords.longitude;

var img_url="http://maps.googleapis.com/maps/api/staticmap?center="

+latlon+"&zoom=14&size=400x300&sensor=false";

document.getElementById("mapholder").innerHTML="<img src='"+img_url+"'>";

}

</script>




This script will display  location in map.

The Javascript substring() method extracts the characters from a string, between two specified Charecter positions in string, and returns the new sub string.Javascript String - substring() Method : Learning Javascript in simple and easy steps. A beginner's tutorial containing complete knowledge of Javascript Syntax .

Javascript substring()  syntax : 

String.substring( from [, to ] )

This Javascript substring() method extracts the characters from a string between "from" and "to ", not including "to" itself.

Some Notes about Javascript  Substring() Method:

If 'from' equals 'to', it returns an empty string.
If 'to' is omitted, it extracts characters to the end of the string.
If either argument is less than 0 or is NaN, it is treated as if it were 0.
If either argument is greater than string’s length, either argument will use string’s length.
If from >to, then substring will swap those 2 arguments.


Example of Javascript substring() Method :-


<script>

var str="Hello Javascript substring method";
document.write(str.substring(3,3)+"<br />");
document.write(str.substring(3)+"<br />");
document.write(str.substring(3,0)+"<br />");
document.write(str.substring(3,7)+"<br />");
document.write(str.substring(7,3)+"<br />");

</script>

The output of the code above will be:

empty string
lo Javascript substring method
Hel
lo J
lo J


Top 10 Javascript Article


No. Title Read
1 Javascript Example-Validate email address in Javascript-Regex Read
2 javascript validation to a textfield to check for null. Read
3 Javascript Code: Live Clock on webpage Read
4 Javascript Code:Add a Print button for page Read
5 Javascript Code: Back and forward button Read
6 Change the Background color of the page Read
7 Javascript Code: Indentify your browser Read
8 Javascript Code: Close the browser Window on button click Read
9 Don't let the user use right click on mouse |Disable mouse right click Javascript code Read
10 How to display a message box when page opens Read


Email Validation: Cross browser Email Validation in JS. JavaScript for Email Address Validation with explanation of the code.The script on this page has been updated to deal with cross-browser issues. Learn how to validate a users email address using Javascript.

Using Regular Expressions is probably the best way. Here's is an function Which will return true if Email is a Valid email and false if email is not valid .



<script>
 
  function validateEmail(email) {
    var regstring = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\
".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA
-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return regstring.test(email);
}
 
 
</script>


But keep in mind that one should not rely only upon JavaScript validation. JavaScript can easily be disabled. This should be validated on the server side as well.


Textbox empty check using javascript,empty textbox validation with javascript ,JavaScript tutorial validate form: Textboxes,Client Side Validation using JavaScript for textbox empty check . how to write javascript alert message for empty textbox , javascript validation to a textfield to check for null.

If you have a textbox and you want to check that the box must not be null using javascript. the below javascript code will help you.


JavaScript Example Code


<script>
  function checknull()
  {
    if(document.getElementById("txttext").value=="")
    {
      alert("Please enter value.");
      return false;
    }
  }
</script>


You just call this function on Blur to event to check textbox is empty or having value.
onblur=" checknull() ;" -- add this to text box property Like below

<asp:TextBox ID="txttext" runat="server" Text="" onblur=" checknull();"></asp:TextBox>

All The Best !!!



If you have  textbox in a form,when a user submits the form,it should check whether the user has filled it or not .The below javascript code will check whether a use filled the text box or left it the default value.this query will validate textbox. 

I am trying to validate a text box so that if the default value for the text box or a blank value is provided, it prevents the form from being submitted.


Javascript code is as follows


  <script  >
   function checkForm()
    {
  
    if (form1.elements['txttext'].value == "" || form1.elements['txttext'].value == "Default Value")
    {
        alert("Please Enter the value in textbox");
        form1.elements['txttext'].focus();
        return false;
    }
      else
       {
        form1.submit();
        return true;
       }
       return true;
}

</script>

 Aspx page code is as follows

<asp:TextBox ID="txttext" runat="server" Text="Default Value"></asp:TextBox>
    <asp:Button ID="btnsubmit" runat="server" Text="submit" OnClientClick="return checkForm()" />

Older Posts Home

Most Read

  • How to Capitalize the First Letter of All Words in a string in C# ?
  • keyboard shortcuts For Windows
  • List Of Best Free WordPress Plugins : 2012
  • Read Write XML Data-Read Write XML File Using C#, VB.NET In Asp.Net
  • How to Shake Internet Explorer - Javascript Code
  • How to Choose a Nice Topic for your Blog .
  • Free Search Engine Submission List ,search engine optimization
  • Number validation in Textbox of ASP.NET Using Regular Expression validator
  • Javascript:Percentage Gain Javascript Calculator
  • .Net Interview Questions and Answers on OOPS | OOPS Frequently Asked Questions
Google
Custom Search Bloggers - Meet Millions of Bloggers

Join Us On FaceBook

  • Recent Posts
  • Comments

All Topics

  • ▼  2014 (10)
    • ▼  January (10)
      • ASP.NET Interview Question : difference between ge...
      • Dot Net Framework:What is the .NET Framework?
      • Dot NET Framework - .NET Framework Interview Quest...
      • What is the differences between MVC2,MVC3 and MVC4...
      • Is try catch is using a good coding (exception han...
      • What is the use of Just - In - Time (JIT)?
      • What is GUID , why we use it?,how to create a GUID
      • How to Rename database table column in sqlserver
      • How to Rename Database in sqlserver
      • Asp.net Example Calendar Control
  • ►  2013 (14)
    • ►  October (1)
    • ►  April (2)
    • ►  March (11)
  • ►  2012 (142)
    • ►  December (25)
    • ►  October (1)
    • ►  September (9)
    • ►  August (2)
    • ►  July (7)
    • ►  June (2)
    • ►  April (5)
    • ►  March (27)
    • ►  February (27)
    • ►  January (37)
  • ►  2011 (23)
    • ►  December (3)
    • ►  November (6)
    • ►  October (12)
    • ►  September (2)
  • ►  2009 (1)
    • ►  June (1)

Tips & Tricks

  • What is good One Blog and Many Categories, or Many Blogs with One Categories?
  • Adding Twitter tweet button to each Blogger posts.
  • How to Choose a Nice Topic for your Blog .
  • Embedding YouTube Videos ,movie in your blog
  • Facebook iFrame Apps – Getting Rid of Scrollbars
  • Facebook Analytics:How to Set Up Your Website or Blog with Facebook Insights for Domains
  • How To Add Perfect Share Box to Blogger
  • Blogger Free Images Hosting Tip,Free unlimited bandwidth image hosting for Blogger blogs
  • Add “Link to this post” codes below Each blogger posts
  • Free Search Engine Submission List ,search engine optimization
  • Adsense Tips for Maximum CTR
  • List Of Best Free WordPress Plugins : 2012
2012 tectopix. All rights reserved.
Designed by tectopix