This topic is locked
[SOLVED]

 Auto save if checkbox checked

2/14/2018 12:39:11 PM
ASPRunner.NET General questions
T
Tim author

Hello,
On my add page I want to "auto-save" the record when a text field losses focus, but only if a checkbox field on the same add page has been selected. I use a field event on the text field, which is set to fire on "change", and in the "client after" section I have this code:
------------------------

var ctrlas = Runner.getControl(pageid,'AutoSave');
if (ctrlas.getValue().ToString() == "1") {

$("#saveButton1").trigger('click');

}

------------------------
But this doesn't seem to work. Can anyone see what I'm doing wrong?
If I just have the auto-save code (i.e. $("#saveButton1").trigger('click'); ) it works, so it seems to be something with the "if" statement.
Thanks,

Tim

admin 2/14/2018

ToString() is a C# function, in Javascript you need to use toString() and you simply don't need it here. The following would be a better version:

var ctrlas = Runner.getControl(pageid,'AutoSave');
if (ctrlas.getValue() == "1") {

$("#saveButton1").trigger('click');

}


If this doesn't work you need to set a breakpoint and step through the code to see what ctrlas.getValue() returns. For checkboxes it can be "on" and not "1".

T
Tim author 2/14/2018

It's always so obvious once someone points it out! Thank you so much for the very quick reply and excellent guidance.
Tim