This topic is locked
[SOLVED]

 Automatically update one field when another is updated

4/14/2016 10:24:28 AM
ASPRunner.NET General questions
Pete K author

I know this is going to be complicated and involve JavaScript -- something I'm not good with. But I would appreciate any help getting started.
So I have an add record page with three relevant fields to this question: Start Date (date field in db), Start Time (time field), and Registration Deadline (DateTime). (Screenshot)
When the user edits the start date and start time fields, I need the registration deadline to automatically default to the combined values of start date and start time. Of course, they need to be able to overwrite this value, which is why I don't just make the field auto-compute and do it all on the database (my preference).
Ideas?

J
JosefTK 4/14/2016

Use Trigger in MS-SQL?

J
JosefTK 4/14/2016



Use Trigger in MS-SQL?

Pete K author 4/14/2016

I suppose I could write a trigger that would set the value when adding or editing IF the user leaves the field blank. I have had some bad luck in the past with triggers and performance issues as well as unintended consequences. But that might be the best way to handle this. Thanks for the suggestion.

jadachDevClub member 4/14/2016

If you want Registration Deadline to be editable, then I think you need JavaScript. Triggers will work after the record is saved to the database. This can also be done in an event.

jadachDevClub member 4/14/2016

Peter, you can do something like this on JavaScript OnLoad event:

var ctrlDateTime = Runner.getControl(pageid, 'DateTime');

var ctrlDate = Runner.getControl(pageid, 'Date');

var ctrlTime = Runner.getControl(pageid, 'Time');

function func() {

ctrlDateTime.setValue (ctrlDate.getValue() + ' ' + ctrlTime.getValue());

}

ctrlDate.on('keyup', func);

ctrlTime.on('keyup', func);


In this example, I am using 3 fields:

[Date] [nvarchar]

[Time] [nvarchar]

[DateTime] [datetime]

Pete K author 4/18/2016

Thanks Jerry.