Thursday, 17 October 2013

How to get Lattitude and Longitude from JSON web service in Java Script and shows on map with marker.

This tutorial is helpful for getting lattitude and longitude from json web service in Java Script and it shows on map with marker when user clicks each marker a label open and when user click on the label an alert will called.
Here is The Code:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>Multiple Markers Google Maps</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
        <script src="https://maps.googleapis.com/maps/api/js?v=3.11&sensor=false" type="text/javascript"></script>
        <script type="text/javascript">
        // check DOM Ready
var latArray=new Array();
var longArray=new Array();
        $(document).ready(function() {
            // execute
            getJson();
        });
function createMap(){
(function() {
                // map options
                var options = {
                    zoom: 5,
                    center: new google.maps.LatLng(2.68158, 101.562), // centered US
                    mapTypeId: google.maps.MapTypeId.TERRAIN,
                    mapTypeControl: false
                };

                // init map
                var map = new google.maps.Map(document.getElementById('map_canvas'), options);

                // NY and CA sample Lat / Lng
                var southWest = new google.maps.LatLng(40.744656, -74.005966);
                var northEast = new google.maps.LatLng(34.052234, -118.243685);
                var lngSpan = northEast.lng() - southWest.lng();
                var latSpan = northEast.lat() - southWest.lat();

                // set multiple marker
                for (var i = 0; i < latArray.length; i++) {
                    // init markers
                    var marker = new google.maps.Marker({
                        position: new google.maps.LatLng(latArray[i], longArray[i]),
                        map: map,
                        title: 'Click Me ' + i
                    });

                    // process multiple info windows
                    (function(marker, i) {
                        // add click event
                        google.maps.event.addListener(marker, 'click', function() {
                            infowindow = new google.maps.InfoWindow({
                                content: '<div style="width:100px;height:50px;color:#0ff;font-size:20px;"><div style="position:fixed;height:30px;width:50px;" onclick="openAlert();">Label</div><div style="height:50px;width:50px;position:fixed;margin-left:100px;"><img src="images/cir_star.PNG"/></div></div>'
                            });
                            infowindow.open(map, marker);
                        });
                    })(marker, i);
                }
            })();
}
function getJson(){
$.ajax({
type:"GET",
url:"http://www.json-generator.com/j/bPNwZIlvZu?indent=4",
dataType: "json",
success: function(data){
var len=data.jsontable.length;
for(var i=0;i<len;i++){
latArray[i]=data.jsontable[i].Y;
longArray[i]=data.jsontable[i].X;
}
createMap();
},
error: function(errorMsg){
alert(errorMsg);
}
});
}
function openAlert(){
alert("You Click on Map.");
}
        </script>
    </head>
    <body>
        <div id="map_canvas" style="width: 800px; height:500px;"></div>
    </body>
</html>

Output Like This:

Sunday, 6 October 2013

How to validate Email Phone No and Confirm Password Field in Html with Java script

Here I show how to validate Email,Phone No. and how to check confirm password match with entered password.
If Information is not correctly entered in there corresponding fields then error shown in form of hint in corresponding fields.
Here is My Code.:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
 function validateForm(){
var nameId=document.getElementById("text_name");
var emailId=document.getElementById("text_email");
var phoneId=document.getElementById("text_phone");
var passwordId=document.getElementById("text_password");
var confirmId=document.getElementById("text_confirm_password");
var name=nameId.value;
var email=emailId.value;
var phone=phoneId.value;
var password=passwordId.value;
var confirmPassword=confirmId.value;
if(name==null||name==""){
nameId.placeholder="Enter Name Here";
nameId.focus();
}else if(email==null||email==""){
emailId.placeholder="Enter Email Here";
emailId.focus();
}else if(phone==null||phone==""){
phoneId.placeholder="Enter Phone Number Here";
phoneId.focus();
}else if(password==null||password==""){
passwordId.placeholder="Enter Password Here";
passwordId.focus();
}else if(confirmPassword==null||confirmPassword==""){
confirmId.placeholder="Enter Confirm Password Here";
confirmId.focus();
}else if(emailCheck(email)==false){
emailId.value="";
emailId.placeholder="Enter Valid Email Here";
emailId.focus();
}else if(checkPhone(phone)==false){
phoneId.value="";
phoneId.placeholder="Enter Valid Phone Here";
phoneId.focus();
}else if(checkPassword(password,confirmPassword)==false){
confirmId.value="";
confirmId.placeholder="Password are not Same";
confirmId.focus();
}
 }
        var str;
        function emailCheck(str)
        {
            var at="@";
            var dat=".";
            var lat=str.indexOf(at);
            var lstr=str.length;
            var ldat=str.indexOf(dat);
            if(str.indexOf(at)==-1||str.indexOf(at)==0||str.indexOf(at)==lstr)
               {
                 return false;
               }
            else if(str.indexOf(dat)==-1||str.indexOf(dat)==0||str.indexOf(dat)==lstr)
               {
                  return false;
               }
             else if(str.indexOf(at,lat+1)!=-1)
               {
                 
                   return false;
               }
             else if(str.substring(lat-1,lat)==dat||str.substring(lat+1,lat+2)==dat)
               {
                   
                    return false;
               }
              else if(str.indexOf(dat,lat+2)==-1)
               {
                 
                    return false;
               }
              else if(str.indexOf(" ")!=-1)
                {
                   
                     return false;
                }
              else
                     return true;
        }
var phoneStr;
function checkPhone(phoneStr){
if(!parseInt(phoneStr)){
return false;
}else if(phoneStr.length<10||phoneStr.length>10){
return false;
}else{
return true;
}
}
var confirmStr,passStr;
function checkPassword(passStr,confirmStr){
if(passStr!=confirmStr){
return false;
}else{
return true;
}
}
function goBackFunction(){
window.location.href="index.html";
}
</script>
<style type="text/css">
body {
background-image: url(images/background.png);
}
.text_label { font-family: "Times New Roman", Times, serif;
font-size: 45px;
font-weight: bolder;
color: #FFF;
}
.button_send { font-family: "Times New Roman", Times, serif;
font-size: 40px;
font-weight: bold;
color: #FFF;
background-color: #9ab13f;
height: 55px;
width: 500px;
}
.text_input {
font-family: "Times New Roman", Times, serif;
font-size: 45px;
font-weight: 200;
height: 50px;
}
</style>
</head>

<body>
<div style="position: absolute; height: 76px; width: 765px; left: 0px; top: 2px; background-image: url(images/title_bar_large.png)">
  <div style="position: absolute; height: 51px; width: 120px; left: 21px; top: 11px;"> <img src="images/btn_back.png" width="121" height="51" alt="Back Button" onclick="goBackFunction();" /></div>
  <div class="text_label" style="position: absolute; height: 43px; width: 242px; left: 246px; top: 12px;">Registration</div>
</div>
<div style="position: absolute; height: 1017px; width: 665px; background-color: #E0E0E0; left: 53px; top: 113px;">
  <form method="post" name="forget_password" id="forget_password">
    <table width="521" height="814" align="center">
      <tr>
        <td height="109" align="center"><input name="text_name" type="text" class="text_input" id="text_name" placeholder="Name" size="30" /></td>
      </tr>
      <tr>
        <td height="139" align="center"><input name="text_name2" type="text" class="text_input" id="text_email" placeholder="Email" size="30" /></td>
      </tr>
      <tr>
        <td height="140" align="center"><input name="text_name3" type="text" class="text_input" id="text_phone" placeholder="Telephone Number" size="30" /></td>
      </tr>
      <tr>
        <td height="153" align="center"><input name="text_name4" type="password" class="text_input" id="text_password" placeholder="Password" size="30" /></td>
      </tr>
      <tr>
        <td height="151" align="center"><input name="text_email" type="password" class="text_input" id="text_confirm_password" placeholder="Confirm Password" size="30" /></td>
      </tr>
      <tr>
        <td align="center"><input name="button_send" type="button" class="button_send" id="button_submit" value="Submit" onclick="validateForm();" /></td>
      </tr>
    </table>
  </form>
</div>
</body>
</html>