Jump to content

Automatically update a Date Field when a Text Field has changed


Recommended Posts

I want to set a Comment Date field to the current date time, when the associated Comment has been entered and/or updated on a Details Page of a Search and Report DataPage.

From code found in previous topics, I constructed the following JS script, but sadly it is not working. Any help will sincerely be appreciated
(as updating the field via a Table Trigger creates  too many cascading actions).

PS On the Stack Overflow site, I picked up the suggestion to add an eventlistener statement

MS_FSR_Comment is a TEXT (255) field with  Text Area on the Details page

MS_FSR_CommDt is a Date/Time field

 

<script>
document.getElementById("EditRecordMS_FSR_Comment").addEventListener("change", function(){

SetFSRDate;

});

Function SetFSRDate(){
var entered = document.getElementById("EditRecordMS_FSR_Comment").value;
    if (entered.length > 0) {
var currentdate = new Date();
var datetime = currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/"
                + currentdate.getFullYear() + " "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":"
                + currentdate.getSeconds();
document.getElementById('MS_FSR_CommDt').value = datetime;
}
}
</script>

 

Link to comment
Share on other sites

I'm happy to answer my own topic.

the following script works:

document.getElementById("EditRecordMS_FSR_Comment").onchange = function(){

var entered = document.getElementById("EditRecordMS_FSR_Comment").value;
    if (entered.length > 0) {
var currentdate = new Date();
var datetime = currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/"
                + currentdate.getFullYear() + " "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":"
                + currentdate.getSeconds();
document.getElementById("EditRecordMS_FSR_CommDt").value = datetime;
}
};

And don't forget to set the receiving field to a Text field on the Report Details Page.

(if set as Display Only it cannot be updated)

 

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...