Skip to main content
Nintex Community Menu Bar

Javascript for current Military Time with Rich Text Control in Repeating Section

  • August 22, 2019
  • 2 replies
  • 27 views

Forum|alt.badge.img+1

I am looking to insert the current military time using javascript that is called from a rich text control in a repeating section. I have gotten this script below to work outside of the nintex form but I am having trouble applying it within the nintex form and having it update the single line of text field. 

<script>
function myFunction() { var currentTime = new Date(),
hours = currentTime.getHours(),
minutes = currentTime.getMinutes();
if (minutes < 10) {
minutes = "0" + minutes;
}
if (hours < 10) {
hours = "0" + hours; }
var timeNow = hours + "" + minutes
document.write(timeNow)
}
</script>

 

Here is what I have currently in the custom Javascript section of the Form Settings but it only seems to refresh the form when clicked (the single line of text control I am trying to update is named TimeL:

 

function myFunction() { var currentTime = new Date(),
hours = currentTime.getHours(),
minutes = currentTime.getMinutes();
 
 if (minutes < 10) {
 minutes = "0" + minutes;
}
 if (hours < 10) {
hours = "0" + hours;  

}
 
var timeNow = hours + "" + minutes 
NWF$("#" + TimeL).val(timeNow);};
 
I was originally trying to get this to work with a button control set to javascript, but it appears that you can't put this control into a repeating section. This is why I went to a Rich Text Control and edited the source to call the javascript function.  Any help is much appreciated. 

2 replies

Forum|alt.badge.img+1

Got this working with this code below. I just had to set the single line of text control to TimeL in the Client Id Javascript Variable Name field on the Advanced Tab.

 

Working code:

 

function myFunction() { var currentTime = new Date(),
hours = currentTime.getHours(),
minutes = currentTime.getMinutes();
 
 if (minutes < 10) {
 minutes = "0" + minutes;
}
 if (hours < 10) {
hours = "0" + hours;  

}
 
var timeNow = hours + "" + minutes; 
NWF$("#" + TimeL).val(timeNow);};
 

Forum|alt.badge.img+1

Revised the code and now it is working exactly like I wanted. When I click the Rich Text Button I added in the repeating section, I wanted the javascript to only update the specific Single line of text field within the current section the Rich Text button was clicked. The previous code would sometimes update the row before it, and also take 2 clicks to update the current row if the button was clicked on the 2nd and beyond repeating section row. The following code works on the last row. This assumes you follow the process of adding a repeating row and click the button on the empty section. Note: if you click add repeating row 2 times and then click the button in the second, row it will update the third row, but for the purpose my users will use the form, this will work just fine, becuase they will only add one row at a time and thus the button will update the last/current row:

 

function myFunction() { var currentTime = new Date(),
hours = currentTime.getHours(),
minutes = currentTime.getMinutes();
 
 if (minutes < 10) {
 minutes = "0" + minutes;
}
 if (hours < 10) {
hours = "0" + hours;  }
 
var timeNow = hours + "" + minutes;
NWF$(".singlelineFocus:last input").val(timeNow);};