AdamKeever1
6 years agoQrew Commander
On Click Counter
Two years ago, @lin posted requesting help creating an on click counter. Mark and Dan shared solutions and the post has been closed to commenting so I am posting a new post, post post. When I use the solution Mark provided and am in edit mode on a form, the on click button only increments by one no matter how many times it is clicked and only after the page is refreshed. When I use Dan's solution, I can't get passed syntax errors. I would appreciate any help and/or suggestions.
Mark provided this solution:
var number NewValue = [My counter field] +1;
var text URL = urlroot() & "db/" & dbid() & "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_99=" & ToText($NewValue);
"javascript:" &
"$.get('" &
$url &
"',function(){" &
"$.jGrowl('Children have been added', {life: 5000, theme: 'jGrowl-green'});" &
"});" &
"void(0);"
// replace the 99 with the field ID of the counter field.
Dan provided this solution:
var dbidTable = "YOUR DBID";
var apptoken = "YORU APPTOKEN";
$.ajaxSetup({data: {apptoken: apptoken}});
var fid = 6; // [counter] field
$.get(dbidTable, {
act: "API_DoQuery",
query: "{3.EX." + kRid + "}",
clist: fid
}).then(function(xml) {
console.dirxml(xml);
var oldValue = parseInt($("counter", xml).text());
var newValue = oldValue + 1;
console.log(oldValue, newValue);
$.post(dbidTable, {
act: "API_EditRecord",
rid: kRid,
_fid_6: newValue
}).then(function(xml) {
// done
})
});
Mark provided this solution:
var number NewValue = [My counter field] +1;
var text URL = urlroot() & "db/" & dbid() & "?act=API_EditRecord&rid=" & [Record ID#]
& "&_fid_99=" & ToText($NewValue);
"javascript:" &
"$.get('" &
$url &
"',function(){" &
"$.jGrowl('Children have been added', {life: 5000, theme: 'jGrowl-green'});" &
"});" &
"void(0);"
// replace the 99 with the field ID of the counter field.
Dan provided this solution:
var dbidTable = "YOUR DBID";
var apptoken = "YORU APPTOKEN";
$.ajaxSetup({data: {apptoken: apptoken}});
var fid = 6; // [counter] field
$.get(dbidTable, {
act: "API_DoQuery",
query: "{3.EX." + kRid + "}",
clist: fid
}).then(function(xml) {
console.dirxml(xml);
var oldValue = parseInt($("counter", xml).text());
var newValue = oldValue + 1;
console.log(oldValue, newValue);
$.post(dbidTable, {
act: "API_EditRecord",
rid: kRid,
_fid_6: newValue
}).then(function(xml) {
// done
})
});