Expand my Community achievements bar.

SOLVED

Same script..works in one form but in another keep getting "Date is not a constructor" error.

Avatar

Former Community Member

Using this javascript in one of my forms to timestamp it, (just a simple protected text field.)

form1.MainPage.DateTimeStamp::docReady - (JavaScript, client)

if (form1.MainPage.DateTimeStamp.rawValue == null) {
        var now = new Date();
        form1.MainPage.DateTimeStamp.rawValue = nowtoDateString() + now.toTimeString();
        }

This timestamps the form as it should.  The problem is on another form I'm building I'm using the identical script, (with different absolute paths of course,) and I keep getting a javascript error about date not being a constructor.  I've type the script in ten bajillion times and I'm at a loss for what is causing this.

All I want is a simpel javascrip where I can display the time/date from the users system in a text field.

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

Is there maybe something else in this form called Date ... a subform, field, script object or something that JavaScript would pick up first before the inbuild Date object?

View solution in original post

7 Replies

Avatar

Level 10

Hi,

You are missing a . inbetween "now" and "toDateString()"

Also you can simplify the script as it is in the docReady of the textfield:

if (this.rawValue == null)

{

     var now = new Date();

     this.rawValue = now.toDateString() + " " + now.toTimeString();

}

Hope tht helps,

Niall

Assure Dynamics

Avatar

Former Community Member

As you instructed:

form1.MainPage.DateTimeStamp::ready:form - (JavaScript, client)

if (this.rawValue==null)
{
    var now=new Date();
    this.rawValue=now.toDateString()+""+now.toTimeString();
}

give me this still...

FORM_error.jpg

Avatar

Level 10

Hi,

If the textfield object is on the Master Page, can I suggest moving the script to the docReady event?

Hope that helps,

Niall

Assure Dynamics

Avatar

Former Community Member

still didn't work.

I've used this script in other forms without a problem.  Exact same script in this form...not working.. I'm totally stumped.

Avatar

Level 10

Can you share the form?

If so, you could upload it to a file sharing site like Acrobat.com and then post the published URL here.

Niall

Assure Dynamics

Avatar

Correct answer by
Level 10

Hi,

Is there maybe something else in this form called Date ... a subform, field, script object or something that JavaScript would pick up first before the inbuild Date object?

Avatar

Former Community Member

BROO1 nailed it.  I had a field named "Date".  Changing this to UsageDate fixed the issue and the script time stamped the form just fine.  Thank you very much!