XPages: How do I set a date field using client side js?

I have some validation code that runs as client side js in a “Save” button. If all validations pass, then I want to set a couple date fields before saving the xpage to its data source. I’ve tried using

var currdate = new Date();

var dc = XSP.getElementById(“#{id:DateChg}”);

dc.value = currdate;

But, I get an error “this field is not a valid date”. I also tried parsing the currdate value into a string and saved that into the field, but got the same error.

Is there a special property of the currdate object I need to use? or, where have I gone wrong?

My DateChg field is a hidden input control, set as Date/Time.

tia

Bob

Subject: Re: Setting date field in client-side javascript

What happens if you set it as a text value, e.g. “15/01/2010”?

I created a field displayed as a date with a default value and looked at the source HTML produced - wht is produced is:

<input type=“text” id=“…” name=“…” value=“15/10/2010”…

Note it’s an input field of type text, and the value is also text.

Also, the XML produced makes it an inputText with a converter. I believe the converter is converting the javascript text value into a date when passed to the NotesDocument, and converting the date passed from the NotesDocument to a string for the HTML.

Subject: Can it be the locale ?

Did you try to put your browser in EN-US ? Each locale as different way to present the date wich is convert back in Domino.

Good luck

Subject: Gives the same error…

Saving the date as a string in a Text edit box produces the same error. It’s the date converter that’s producing the error message. Apparently, the dateconverter is called in the addOnLoad function, but I don’t know where this function is to even see why it’s producing the error.

It’s very frustrating as now I cannot save my document at all.

(Note: this is an app in development, not production, so not critical)

Subject: Re: DateConverter & addOnLoad

The addOnLoad is in xspClientDojo.js which, for a standard Notes install, will be in C:\Program Files\IBM\Lotus\Notes\Data\domino\js\dojo-1.3.2\ibm\xsp\widget\layout folder.

What is the date that you have stored in your Notes document? Also what is the server date format (as recorded in the Notes Log), and what is the date format on your browser? Check your Notes field settings on the form. These are the obvious things that spring to mind.

If none of these throw any light on the problem, post your code and I’ll see if I can spot anything.