0

Hello,

I am creating an elearning that tries to record date and time and I am looking for an automated system to do that so that the user won't enter any other information:

As far as now, I only uses

Date Time [ input textbox ]

Is there other way to input date and time so that the information will be accurate?

4
Contributors
7
Replies
57
Views
3 Years
Discussion Span
Last Post by Ketul_1
0

If you want to input the current time (at the time of the insert) then you can use the now(); function. What gets stored is dependant on the field type. If it's just a date field, you get the date (I believe it will be yy default in a YYY-MM-DD format), if it's a datetime field then you'll get the date and time (again, I think the default is a YYYY-MM-DD hh:mm:ss format),

0

It is not a now(); time. It's a time for the class in the future.

I mean the syntax has to be DD-MM-YYYY 00:00:00 AM

for example. If I only use input textbox then the information could be many other information besides that format.

0

What you're looking to do is called "text masking" or "input field masking". It's easy to do with jQuery, however if you haven't done it before, it can be quite daunting to create a custom mask from scratch.

A fast solution is to use one of the masking plugins available for jQuery. Here's the first one that came up on google who's demo page is pretty self-explanatory: http://robinherbots.github.io/jquery.inputmask/ .

Edited by DJBirdi

0

Okay,

Here is what I tried:

index.php

<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.maskedinput.js" type="text/javascript"></script>

<script>
jQuery(function($){
   $("#date").mask("99/99/9999");
   $("#phone").mask("(999) 999-9999");
   $("#tin").mask("99-9999999");
   $("#ssn").mask("999-99-9999");
});
</script>


<div id="date">Please enter Date :<input type="text" id="date" name="date"></div>

There references is taken from this link: masked-input

I wonder what I did wrong since the input is still plain text not masked input.

Edited by davy_yg

1
<div id="date">Please enter Date :<input type="text" id="date" name="date"></div>

ID's cannot be duplicated in the same script. They must be unique. You have <div id="date"> and <input id="date">.

Option 1:
For the <div>, either remove the id arrtibute or change it to a class.

<div class="date">Please enter Date :<input type="text" id="date" name="date"></div>

Option 2:
Change input's id to something else and make sure it's updated in your jQuery

$("#user_date").mask("99/99/9999");

<input type="text" id="user_date" name="date">
0

I have tried both. None of them works. Have you tried using the actual js from the link ?

0

Try This. I hope this code Works for you.

<!doctype html>
<html>
<head>
  <script src="jquery-1.8.3.min.js" type="text/javascript" charset="utf-8"></script>
<script src="jquery.maskedinput.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function() {
        $.mask.definitions['~'] = "[+-]";
        $("#datedate").mask("99/99/9999",{completed:function(){alert("completed!");}});
        $("input").blur(function() {
            $("#info").html("Unmasked value: " + $(this).mask());
        }).dblclick(function() {
            $(this).unmask();
        });
    });

</script>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<div id="date">Please enter Date :<input type="text" id="datedate" name="datedate"></div> 
</body>
</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.