Skip to main content
Question

On Click Counter

  • June 18, 2019
  • 0 replies
  • 74 views

AdamKeever1
Forum|alt.badge.img+2
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
  })
});
This topic has been closed for replies.

If you want the page to refresh after each click to see the counter increase, then you would use this

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(){" &
"location.reload(true);" &
"});" 
& "void(0);"



AdamKeever1
Forum|alt.badge.img+2
  • Author
  • Registered
  • June 19, 2019
Thanks Mark. I tried that and it does not increment for me, but does refresh. So I added the apptoken and it continued to not increment ,but then also stopped refreshing.

Is there a syntax guide for formula URL and formula rich text somewhere?

I added the apptoken like this:

var text URL = URLRoot() & "db/" & Dbid() & "?act=API_EditRecord &apptoken=xxxxxxxxxxxxxxxxxxxxxxx &rid=" & [Record ID#]
& "&_fid_99=" & ToText($NewValue);

I also noticed that my counter field is numeric and there is a function to turn NewValue ToText. Should I be using a text field; I thought the mathematical addition operator would not funtion with text.

Also, when you�re trying to debug these what you do is you just run the pure URL without the JavaScript refresh and then it will reveal any error messages.

I find it hard to believe that it does not increment. Are you updating the correct field in your app. Can you post your actual code. For example it�s highly unlikely that the field do you want to update his field ID 99

AdamKeever1
Forum|alt.badge.img+2
  • Author
  • Registered
  • June 19, 2019
My increment field is fid 686. I did change it and it does not function.

Here is the code revised for my fields:

var number NewValue = [test counter field] +1;

var text URL = URLRoot() & "db/" & Dbid() & "?act=API_EditRecord&apptoken=xxxxxxxxxxxxxxxxxxxxxxx&rid=" & [Record ID#]
& "&_fid_686=" & ToText($NewValue);

When I delete the JavaScript, there is an error stating: column: 0 > Expecting text