Jump to content

Date Input Mask


Recommended Posts

Hi, i have several input fields (Date/time)  for user to need to insert their birth date. As the popup calendar it is a little bit uncomfortable to go many years ago, some of them wants to insert the dates manually, so i need to create a mask with predefine dd/mm/yyyy format to able the users to just insert the numbers and then the field could have the right format to can be inserted. Any idea?

 

Thanks!

Link to comment
Share on other sites

Hello esisov,

 

You can add this code to the Footer (do not forget clicking the Source button and changing FIELDNAME to the name of your field):

<SCRIPT LANGUAGE="JavaScript">function f_a(v_id)
{
return document.getElementById(v_id);
}
f_a('InsertRecordFIELDNAME').maxLength = 10;
f_a('InsertRecordFIELDNAME').onkeyup = function(v_e)
{
v_e = v_e || window.event;
if (v_e.keyCode >= 65 && v_e.keyCode <= 90){
this.value = this.value.substr(0, this.value.length - 1);
return false;
}else if (v_e.keyCode >= 37 && v_e.keyCode <= 40){
return true;
}
var v_value =(this.value.replace(/[^\d]/g, ''));
if (v_value.length==8) {
this.value = (v_value.substring(0,2) + "/" + v_value.substring(2,4) + "/" + v_value.substring(4,8));}
}
</SCRIPT>

Hope it helps.

 

IREN

Link to comment
Share on other sites

  • 9 months later...

Hello Community!

As absolutely newbie in Caspio (as well as in programming anything....) I´ve tried to solve the same problem, as the TO has had, on my page as well with this solution, but it doesn´t work!? :o

Please see screenshots I´ve made:

http://prntscr.com/c6u4s0

http://prntscr.com/c6u5md


Any ideas or suggestions? Thanks in advance for your reply! :)

Link to comment
Share on other sites

I would like to tell additional a small issue with the date in German usage (where date form is usual "DD.MM.YYYY"):

In the above mentioned scrip troubles the "/" a little bit while entering a date and I´ve changed the script as shown below:

<SCRIPT LANGUAGE="JavaScript">function f_a(v_id)
{
return document.getElementById(v_id);
}
f_a('InsertRecordbesteller_geburtsdatum').maxLength = 10;
f_a('InsertRecordbesteller_geburtsdatum').onkeyup = function(v_e)
{
v_e = v_e || window.event;
if (v_e.keyCode >= 65 && v_e.keyCode <= 90){
this.value = this.value.substr(0, this.value.length - 1);
return false;
}else if (v_e.keyCode >= 37 && v_e.keyCode <= 40){
return true;
}
var v_value =(this.value.replace(
.[^\d]/g, ''));
if (v_value.length==8) {
this.value = (v_value.substring(0,2) + "
." + v_value.substring(2,4) + "." + v_value.substring(4,8));}
}
</SCRIPT> 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...