Forums: [SOLVED] Auto save if checkbox checked - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

[SOLVED] Auto save if checkbox checked Rate Topic: -----

#1 User is offline   timnorvel 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 253
  • Joined: 21-September 07

Posted 14 February 2018 - 05:39 PM

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
0

#2 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 15830
  • Joined: 03-February 03

Posted 14 February 2018 - 06:04 PM

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".
Best regards,
Sergey Kornilov
0

#3 User is offline   timnorvel 

  • Advanced Member
  • PipPipPip
  • Group: Members
  • Posts: 253
  • Joined: 21-September 07

Posted 14 February 2018 - 07:30 PM

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

Tim
0

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked