Jump to content

How to add timestamp depending on the presence of File in the File input field


Recommended Posts

To add timestamp depending on the presence of File in the File input field you need to add one additional HTML field and insert this snippet of code:

 

<script type="text/javascript">function addTimestamp (fileInputId, timestampInputId) {
    
 var fileInput = document.getElementById(fileInputId);
 fileInput.addEventListener('change', function () {
  
   if (fileInput.files.length !== 0 ){
    document.getElementById(timestampInputId).value = '[@cbTimestamp*]';
   }
 
 });

};

addTimestamp('File_Id_1', 'Date_Input_Id_1');
addTimestamp('File_Id_2', 'Date_Input_Id_2');
addTimestamp('File_Id_3', 'Date_Input_Id_3');
.
.
.
addTimestamp('File_Id_X', 'Date_Input_Id_X');
</script>

 

fileInputId: ID of the File field

timestampInputId: ID of the Date Field

 

You can add as many functions depending on the number of your file fields.
To find the ID of fields use Developer tools and "Inspect"

1.JPG

 

NOTE! 
You need to use the proper type of short date to save the value.
Example - 20/08/2018; dd/MM/ yyy

 

1.JPG

Link to comment
Share on other sites

  • 2 weeks later...

@edujobs2k18

To implement your workflow you can use this code:

 

<script type="text/javascript">function addTimestamp (fileInputId, timestampInputId, textInptId) {
    
 var fileInput = document.getElementById(fileInputId);
 fileInput.addEventListener('change', function () {
  
   if (fileInput.files.length !== 0 ){
    document.getElementById(timestampInputId).value = '[@cbTimestamp*]';
    document.getElementById(textInptId).value = 'New';
   }
 
 });

};

addTimestamp('fileInputId1', 'timestampInputId1', 'textInptId1');
addTimestamp('fileInputId2', 'timestampInputId2', 'textInptId2');
addTimestamp('fileInputId3', 'timestampInputId3', 'textInptId3');
.
.
.
addTimestamp('fileInputId_x', 'timestampInputId_x', 'textInptId_x');

</script>

 

Just find the IDs of the text fields using Developer Tools of the browser and insert these values instead of 'textInputId1', 'textInputId2'.....'textInputId_x'.

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