Showing results for 
Search instead for 
Did you mean: 
Not applicable

Javascript question


I have a JavaScript to set a control value based on another control.

But I want  this value to be editable.

But on submit, the value is changed back to calculated value and user entered value disappears.

Can you suggest a solution for this?

0 Kudos
2 Replies
Automation Master
Automation Master

Re: Javascript question


Can you post the type of controls you are using, as well as the code you are attempting to trigger?  The more information you give, the easier it will be for the community to help you out.


0 Kudos
Not applicable

Re: Javascript question


Thank you for reaching out to me.

I am using a “Single Line of Text”.

My requirement is : This single line of text should show the difference between the start date and end date. Based on this Date difference, it should show the working hours.


Start Date: 04/21/2014, End Date : 04/22/2014 (Chosen by user).

Date Difference Should be auto calculated and stored in Single line of text . In this example it should return 2 days.

No of working hours Should be auto calculated and stored in another Single line of text . In this example it should return 16 hours.

But I want users to be able to change this 16 hours to any value (example 12 hours).

I am using JavaScript currently and it works fine . But user changed value is not being captured when the submit is clicked. Because the JavaScript is called again on submit button and it calculates the value again.

function calculateDates(source, arguments)


var varStartDate = NWF$('#' + varStartDate);

var varEndDate = NWF$('#' + varEndDate);

// get date from first date picker

var startdepart = parseDate(varStartDate.val(),'mm/dd/yy');

// get date from first date picker

var enddepart = parseDate(varEndDate.val(),'mm/dd/yy');

var timeDiff = Math.abs(enddepart.getTime() - startdepart.getTime());

var diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24));

var noofhours = diffDays*8;



arguments.IsValid = true;


function parseDate(dateString, userFormat) {

var delimiter, theFormat, theDate, month, date, year;

// Set default format if userFormat is not provided

userFormat = userFormat || 'yyyy-mm-dd';

// Find custom delimiter by excluding

// month, day and year characters

delimiter = /[^dmy]/.exec(userFormat)[0];

// Create an array with month, day and year

// so we know the format order by index

theFormat = userFormat.split(delimiter);

//Create an array of dateString.

theDate = dateString.split(delimiter);

for (var i = 0, len = theDate.length; i < len; i++){

//assigning values for date, month and year based on theFormat array.

if (/d/.test(theFormat)){

date = theDate;


else if (/m/.test(theFormat)){

month = parseInt(theDate, 10) - 1;


else if (/y/.test(theFormat)){

year = theDate;



return (new Date(year, month, date));


Do let me know for more questions


Ankita Rikhab Chand

Verdesian Life Sciences

509 547 8234 X138 (Office)

864 901 3389 (Mobile)<>

0 Kudos