
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.

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
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()" />
