save value to database immediately after onchange event is fired

can I save a value to the database immediately after onchange event is fired in a form (editable grid) ?

I need some example ajax code to do this. Thanks

Re: save value to database immediately after onchange event is fired

You could use the sc_exec_sql macro to update a value immediately after ajax onChange is fired. I.e. create an Ajax event onChange to a field of your choice, then run sc_exec_sql.

Ajax onChange:
sc_exec_sql (“update myTable set Field = ‘{Field}’ where ID = ‘{ID}’”);

regards,
Bartho

Re: save value to database immediately after onchange event is fired

but how to identify id on each row on grid (not form) bartho, did you know how?

regards
masbro

Re: save value to database immediately after onchange event is fired

That’s right. It’s a editable grid form, so how to determine the id of the current row?

Re: save value to database immediately after onchange event is fired

@masbro, on a Grid you would use the onRecord event. But that will depend on what you are trying to do.

@Freezer, on a Editable Grid Form you won’t need to determine the id of the current row (Scriptcase does it).

Re: save value to database immediately after onchange event is fired

@bartho: you’re right, in editable grid scriptcase knows what record (id) the focus is on. thanks.

To prevent invalid update to database when inserting new record (no id value yet):


if ( {id} != '' ) {
   sc_exec_sql ("update myTable set Field = '{Field}' where ID = '{ID}'");
}