Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 7381 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

On my Web Companion site, web users are required to input dates for events they wish to enter in the database. They are instructed to enter the year in four-digit format (ie 2004). People being people, some enter the year in two-digit format (ie 04).

When operating locally, FMP assumes the two-digit dates are for the year 2000 and thereafter. Thus, if a user enters 5/10/04, FMP enters 5/10/2004 in the database. Operating online, however, two-digit dates default to 1900 when entered for some reason. That is, if a user inputs 5/10/04, the date entered in the database is 1904.

Any idea why this is, and what I can do about it? Thanks, friends.

Posted

Hi, Rob! FM century-guessing heuristics do not work from external sources (web, imports, etc.). I'd suggest doing it Garry's way and use JavaScript. You can either reject their 2-digit years or you can fix them for them. If you stay in FM, you'll have to fix them somehow after submission by using a script or calculations but it's probably better to fix them before they go in if you can.

These threads may/may not help...

http://www.fmforums.com/threads/showflat.php?Cat=0&Board=UBB22&Number=81227

http://www.fmforums.com/threads/showflat.php?Cat=0&Board=UBB22&Number=85698

Posted

Steve and Garry --

I adapted Garry's script (link above) and dropped it after my <head> as follows:

<script>

function fixdate()

{

sDate = document.form1.Start Date.value.split("/")

if (sDate[2] < 2000)

{

sDate[2] = (sDate[2] - 0) + 2000 ;

document.form1.Start Date.value = sDate.join("/") ;

} ;

document.form1.submit() ;

} ;

</script>

My field "Start Date" is in US format, i.e., MM/DD/YYYY. (I also use a field "End Date", but I'll deal with that later.) In the form markup, I inserted the following:

<form method=post action="FMPro" name="form1" onsubmit="return(VerifyForm('form1'));"><onsubmit="Javascript:fixdate(); return false"><input type=hidden name="-new"><input type . . . . et cetera et cetera

Doesn't seem to work for me. Throws off no errors, but the two-digit years are always recorded with a 19** prefix.

Garry's scripts always work, so I'm sure I'm messing something up.

Posted

Try this:

<script>

function fixdate()

{

sDate = document.form1.elements["Start Date"].value.split("/");

if (sDate[2] < 2000)

{

sDate[2] = (sDate[2] - 0) + 2000 ;

document.form1.elements["Start Date"].value = sDate.join("/") ;

} ;

eDate = document.form1.elements["End Date"].value.split("/");

if (eDate[2] < 2000)

{

eDate[2] = (eDate[2] - 0) + 2000 ;

document.form1.elements["End Date"].value = eDate.join("/") ;

} ;

document.form1.submit() ;

} ;

</script>





<form method="post" action="FMPro" name="form1" onsubmit="Javascript:fixdate(); return false">

Good Luck.

Garry

Posted

Once again Garry shows how its done. The script works like a charm.

At the risk of sounding like a greedy pig, I wonder if the script can be combined with a second "onsubmit" to validate the form. My understanding is that an "onsubmit" can have only one function, and there can only be one "onsubmit" per form. Hence, either my form can run Garry's script or it can validate my form, but not both. At present, I've written:

<form method=post action="FMPro" name="form1" onsubmit="return(VerifyForm('form1'));">

My guess is I can't string "Javascript:fixdate(); return false" in this line. (Please don't do any more work without sending me an invoice!)

Best, RR

Posted

Rob,

This onsubmit is OK:

onsubmit="Javascript:fixdate(); return false">


You can have as much Javascript as you like in there. Hence:


 onsubmit="Javascript:fixdate(); fmvalidate(); return false">




However, I would combine the validation and the date fix into the one Javascript function.



Be aware that I use this line to submit the Form from within the Javascript function:


document.form1.submit() ;

I do not return "true" to the "onsubmit=" parameter. This method is no better than the conventional method of returning "true" or "false", however I believe that I have more control wink.gif

I'm mostly extracting these functions from pages that I have already written, hence, not a great deal of effort in modifying them for general use on the Forum. If I write something specific for somebody I would usually charge smile.gif

All the best.

Garry

This topic is 7381 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.