如何将系统物理地址插入数据库

时间:2017-05-16 09:49:54

标签: javascript pouchdb

如何在提交表单时将系统物理地址插入数据库。当我注册有用户详细信息时,应自动将系统物理地址注册到数据库。请打电话给我,我该怎么办。

我正在使用 - HTML,javascript和PouchBD

以下是我的注册码。 register.html 在此我使用javascript进行了valiodation。

<!DOCTYPE html>

<html>
<head>
    <title>Insurance:Register User</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>        
    <script src="js/jquery.min.js"></script>        
    <script>if (window.module) module = window.module;</script>

    <link href="css/datepicker.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="css/finalprivate.css">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
    <link href="css/bootstrap-theme.min.css" rel="stylesheet" type="text/css"/>
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <script src="js/bootstrap.min.js" type="text/javascript"></script>
    <script src="js/bootstrap-datepicker.js" type="text/javascript"></script>
    <script src="js/login.js"></script>



</head>
<body background="images/lbbackground.jpg" >
    <nav id="myNavbar" class="navbar navbar-default navbar-inverse" role="navigation">
        <!-- Brand and toggle get grouped for better mobile display -->
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbarCollapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <!--<a class="navbar-brand" href="index.html">HOME</a>-->
            </div>
            <!-- Collect the nav links, forms, and other content for toggling -->
            <div class="collapse navbar-collapse" id="navbarCollapse">
                <ul class="nav navbar-nav">
                    <li class="dropdown">
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#" >Survey
                            <span class="caret"></span></a>
                        <ul class="dropdown-menu">
                            <li class="dropdown dropdown-submenu">
                                <a  class="dropdown-toggle" data-toggle="dropdown" href="#">Final Survey</a>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a href="finalprivate.html">Private</a>
                                    </li>
                                    <li >
                                        <a href="finalcommercial.html">Commercial</a>
                                    </li>
                                </ul>
                            </li>
                            <li class="dropdown dropdown-submenu">
                                <a  class="dropdown-toggle" data-toggle="dropdown" href="#">Spot Survey</a>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a href="spotsurveyprivate.html">Private</a>
                                    </li>
                                    <li >
                                        <a href="spotsurveycommercial.html">Commercial</a>
                                    </li>
                                </ul>
                            </li>
                            <li class="dropdown ">
                                <a  href="reinspection.html">Re-inspection</a>
                            </li>
                        </ul>
                    </li>

                    <li><a href="reporthistory.html">Report History</a></li>
                    <li><a href="company.html">Insurance Companies</a></li>
                    <li><a href="personal.html">Personal Details</a></li>
                    <li><a href="accounts.html">Accounts</a></li>
                    <li  class="active"><a href="register.html">Register</a></li>
                    <li ><a href="login.html">Login</a></li>
                    <li><a  href="logout.html" ">Logout</a></li>
                    <li><a  href="settings.html">Settings</a></li>

                </ul>
            </div>
        </div>
    </nav>
    <article class="container" id="boxshadow" style="background-color:white;width:50%;">
        <form action="" method="POST" name="vform" id="regForm"> 
            <fieldset>
                <legend><strong>Register</strong></legend>
                <div class="row">
                    <div class="col-xs-3 ">
                        <!-- <label>User Name:</label> -->
                    </div>
                    <div class="col-xs-5">
                        <input class="form-control" name="fname" id="fname" type="text" placeholder="First Name">
                        <div id="fname_error" name="val_error"></div>
                    </div>
                </div><br>

                <div class="row">
                    <div class="col-xs-3 ">
                        <!-- <label>User Name:</label> -->
                    </div>
                    <div class="col-xs-5">
                        <input class="form-control" name="lname" id="lname" type="text" placeholder="Last Name">
                        <div id="lname_error" name="val_error"></div>
                    </div>
                </div><br>

                <div class="row">
                    <div class="col-xs-3 ">
                        <!-- <label>User Name:</label> -->
                    </div>
                    <div class="col-xs-5">
                        <input class="form-control" name="uname" id="uname" type="text" placeholder="User Name">
                        <div id="uname_error" name="val_error"></div>
                    </div>
                </div>   

                <br>
                <div class="row">
                    <div class="col-xs-3 ">
                        <!-- <label>Password:</label> -->
                    </div>

                    <div class="col-xs-5">
                        <input type="Password" class="form-control" name="password" id="password" placeholder="Password">
                        <div id="password_error" name="val_error"></div>
                    </div>
                </div>
                <br>

                <div class="row">
                    <div class="col-xs-3 ">
                        <!-- <label>Password:</label> -->
                    </div>

                    <div class="col-xs-5">
                        <input type="Password" class="form-control" name="cpassword" id="cpassword" placeholder="Confirm Password">
                        <div id="cpassword_error" name="val_error"></div>
                    </div>
                </div>
                <br>

                <div class="row">
                    <div class="col-xs-3 ">
                        <!-- <label>User Name:</label> -->
                    </div>
                    <div class="col-xs-5">
                        <input class="form-control" name="email" id="email" type="text" placeholder="Email ID">
                        <div id="email_error" name="val_error"></div>
                    </div>
                </div>
                <br>
                <div class="row">
                    <div class="col-xs-3 ">
                        <!-- <label>User Name:</label> -->
                    </div>
                    <div class="col-xs-5">
                        <input class="form-control" name="mobileno" id="mobileno" type="text" placeholder="Mobile Number">
                        <div id="mobileno_error" name="val_error"></div>
                    </div>
                </div>

                <br>
                <div class="row">
                    <div class="col-xs-3 ">
                        <label></label>
                    </div>

                    <div class="col-xs-2 col-md-3 col-md-offset-1">
                        <input type="submit" class="form-control btn btn-primary" name="click" id="submitbtn" value="Register" >
                    </div>
                    <span id="message" style="color: red;"></span>

                </div>
                <br>                     

            </fieldset>

        </form>
    </article>
    </body>
     <script src="js/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/login.js"></script>
    <script src="js\pouchdb-6.1.2.min.js"></script>
    <script src="js/serial.js"></script>

    <script src="js/datatables.min.js"></script>
    <script src="js/memorystream.js"></script>
    <script src="js/pouchdb.replication-stream.js"></script>
    <script src="js/register.js"></script>

    <script type="text/javascript">

$("#regForm").submit(function(e){
e.preventDefault();

 var fname = document.forms["vform"]['fname'];
      var lname = document.forms["vform"]['lname'];
      var uname = document.forms["vform"]['uname'];
      var password = document.forms["vform"]['password'];
      var cpassword = document.forms["vform"]['cpassword'];
      var email = document.forms["vform"]['email'];
      var mobile = document.forms["vform"]['mobileno'];

      //Validation
      var fname_error = document.getElementById("fname_error");
      var lname_error = document.getElementById("lname_error");
      var uname_error = document.getElementById("uname_error");
      var password_error = document.getElementById("password_error");
      var cpassword_error = document.getElementById("cpassword_error");
      var email_error = document.getElementById("email_error");
      var mobileno_error = document.getElementById("mobileno_error");

      //Setting All event Listners
      fname.addEventListener("blur", fnameVerify, true);
      lname.addEventListener("blur", lnameVerify, true);
      uname.addEventListener("blur", unameVerify, true);
      password.addEventListener("blur", passwordVerify, true);
      cpassword.addEventListener("blur", cpasswordVerify, true);
      email.addEventListener("blur", emailVerify, true);
      mobileno.addEventListener("blur", mobilenoVerify, true);
      Validate();
});


      //Validating
      function Validate()
      {

        if (fname.value == "")
        {
          //fname.style.border="1px solid red"              
          fname_error.innerHTML="<span style='color:red'> First  Name is required";
          fname.focus();
          return false; 
        }

        if (lname.value == "")
        {
          //lname.style.border="1px solid red"
          lname_error.innerHTML="<span style='color:red'>Last Name is required";
          lname.focus();
          return false; 
        }

        if (uname.value == "")
        {
          //uname.style.border="1px solid red"
          uname_error.innerHTML="<span style='color:red'>User Name is required";
          uname.focus();
          return false; 
        }

        if (password.value == "")
        {
          //password.style.border="1px solid red"
          password_error.innerHTML="<span style='color:red'>Password is required";
          password.focus();
          return false; 
        }

        if (password.value != cpassword.value)
        {
          //cpassword.style.border="1px solid red"
          cpassword_error.innerHTML="<span style='color:red'>Password dont match";   
          cpassword.focus();           
          return false; 
        }

        if(email.value == "")
        {
          //email.style.border="1px solid red"
          email_error.innerHTML="<span style='color:red'>Email is required";
          email.focus();
          return false; 
        }

        var x = document.forms["vform"]["email"].value;
        var atpos = x.indexOf("@");
        var dotpos = x.lastIndexOf(".");
        if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) {
            //alert("Not a valid e-mail address");
            email_error.innerHTML="<span style='color:red'>Not a valid e-mail address";
            email.focus();
            return false;
        }

        if(mobileno.value == "")
        {
          //mobileno.style.border="1px solid red"
          mobileno_error.innerHTML="<span style='color:red'>Mobile number is required";
          mobileno.focus();
          return false; 
        }
        var numbers = /^[0-9]+$/;
        if (mobileno.value.match(numbers)) 
        {
          //return true;
        }
        else
        {
          //mobileno.style.border="1px solid red"
          mobileno_error.innerHTML="<span style='color:red'> Mobile number must be numbers only";  
          mobileno.focus();  
          return false;
        }

        if(mobileno.value.length !=10)
        {
          //mobileno.style.border="1px solid red"
          mobileno_error.innerHTML="<span style='color:red'> Mobile number must be 10 digit";
          mobileno.focus();
          return false; 
        }


            //regEvent();
            addregister();

      }


        function fnameVerify()
        {
          if(fname.value !="")
          {
            fname_error.innerHTML = "";
            return true;
          }
        }

        function lnameVerify()
        {
          if(lname.value != "")
          {
            lname_error.innerHTML= "";
            return true;
          }
        }

        function unameVerify()
        {
          if(uname.value != "")
          {
            uname_error.innerHTML= "";
            return true;
          }
        }

        function passwordVerify()
        {
          if(password.value != "")
          {
            password_error.innerHTML= "";
            return true;
          }
        }

        function cpasswordVerify()
        {
          if(cpassword.value != "")
          {
            cpassword_error.innerHTML= "";
            return true;
          }
        }

        function emailVerify()
        {
          if(email.value != "")
          {
            email_error.innerHTML= "";
            return true;
          }
        }

        function mobilenoVerify()
        {
          if(mobileno.value != "")
          {
            mobileno_error.innerHTML = "";
            return true;
          }
        } 


</script>
</html>

以下是我的javascript代码,用于将数据保存到 pouchDB 。 register.js

var db=new PouchDB('register_details');

function addregister(){
  var f=document.getElementById('fname').value;
  var l=document.getElementById('lname').value;
  var u=document.getElementById('uname').value;
  var p=document.getElementById('password').value;
  var e=document.getElementById('email').value;
  var m=document.getElementById('mobileno').value;
  //console.log(f,l,u,p,e,m);

  doc={
_id:u,
fname:f, 
lname:l,
password:p,
email:e,
mobileno:m
  }
 db.put(doc,function(error,response){

if(!error){
  //document.getElementById("message").innerHTML="inserted";
  alert('Registered successfully!');

    document.getElementById('fname').value='';
    document.getElementById('lname').value='';
    document.getElementById('uname').value='';
    document.getElementById('password').value='';
    document.getElementById('cpassword').value='';
    document.getElementById('email').value='';
    document.getElementById('mobileno').value='';



}
else{
  alert('User name already exist!');
  //document.getElementById("message").innerHTML=" Not inserted";
}
  });
}

1 个答案:

答案 0 :(得分:0)

没有。如果您只想使用JavaScript访问MAC地址,那么它就不可能了。如果您正在使用Java代码(applet)或使用ActiveX控件在IE浏览器上,那么您可以获得它。

JavaScript无法获取MAC地址。