Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • To display the server time in the input box with the help of ajax

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 148
    Comment on it

    Here we are making two simple text box one for the name which is filled by the user and the other is the input box for the time which is automatically called with the help of jQuery-ajax. First of all we make a simple form with two input fields one is for the name and other is for the time. The name input box is entered  by the user and soon as the name text box loses focus the value would automatically fetch from the server. Here is code define below:

    <html>
    <body>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script type="text/javascript">
    
    //jquery-ajax function used to get the server time
    $(document).ready(function(){
       $("#name").change(function(){
           $.ajax({
                url: "serverTime.php", 
                success: function(result){
                   $("#time").val(result);
                }
          });
       });
    });
    
    //-->
    </script>
    
    
    
    <form name='myForm'>
    Name: <input type='text'  name='username' id="name" > <br />
    Time: <input type='text' name='time' id="time"/>
    </form>
    </body>
    </html>

    This file is saved with the order.html 

    Then we make other file to get the time of the server that file would be saved with the serverTime.php.

    Here is the code for the file.

    <?php
    echo date("H:i:s"); 
    ?>

    Then we run the code in the local host to see the output.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: