Skip to main content
Question

Javascript refresh and position to a spot on the form

  • Mar 21, 2015 1:55 AM UTC
  • 0 replies
  • 255 views

This works wonderfully. But is there an easy way to get it to also position to a spot on the form when it refreshes? Say to an anchor tag placed on the form like this?

"<a name=DealerClaim></a>"



var text NewStatus= If([Backorder Status]="Filled", "On Backorder", "Filled");

var text URL = URLRoot() & "db/" & [_DBID_BACKORDER_LINES] & "?act=API_EditRecord"
& "&rid=" & ToText([Record ID#])
& "&_fid_6=" & $NewStatus;

"javascript:" &
"$.get('" &
$URL &
"',function(){" &
"location.reload(true);" &
"});"
& "void(0);"



This topic has been closed for replies.

  • Observing
  • Mar 21, 2015 9:54 PM UTC
Try this - see the bolded text to replace the line with "location.reload(true)"

var text NewStatus= If([Backorder Status]="Filled", "On Backorder", "Filled");

var text URL = URLRoot() & "db/" & [_DBID_BACKORDER_LINES] & "?act=API_EditRecord"
& "&rid=" & ToText([Record ID#])
& "&_fid_6=" & $NewStatus;

"javascript:" &
"$.get('" &
$URL &
"',function(){" &
"location.href = location.href + '&d=' + Date.now() + '#DealerClaim';" &
"});"
& "void(0);"


This constructs a new URL to go to. location.href is the current URL, and that's normally where the browser goes when you do location.reload(true).

If you just put #DealerClaim at the end, the problem is that the browser doesn't refresh, and just jumps down to the anchor (which is normal browser behavior for anchors when you're on the same page already).

So what we do is change the URL dynamically by putting in '&d=' + Date.now() - which puts a timestamp on the URL. e.g. &d=1426960116976

Since the URL is now different every time you press the button, the browser reloads the page, and then jumps to the anchor position.

Wonderful and thank you for the detailed explanation!

  • Observing
  • Mar 21, 2015 10:22 PM UTC
You're welcome!

AdamKeever1
Forum|alt.badge.img+2
  • Qrew Commander
  • Mar 1, 2018 8:50 PM UTC
Can this be applied to a section title or tab in a form?

  • Qrew Corporal
  • Mar 1, 2018 9:29 PM UTC
>Can this be applied to a section title or tab in a form?

Adding a hash or fragment identifier (this is what the string after the # is called) to the end of the URL will result in the browser scrolling to that position. This is a general capability so you can form pinpoint references to a position on a page. Here is a pinpoint reference to your comment in the forum:
https://community.quickbase.com/
quickbase/
topics/
javascript-refresh-and-position-to-a-spot-on-the-form
#reply_19360840
You can locate the hash by inspecting the source - in Chrome right click, select inspect and look for name or id attribute nearby. That is the hash or fragment identifier to use. Here is a screenshot of me inspecting an arbitrary id in a random QuickBase form page that I had open revealing the hash is #tdf_0 for that particular position of the page:


JillEngle
Forum|alt.badge.img+2
  • Qrew Cadet
  • Mar 1, 2018 9:48 PM UTC
Can it be applied generically so that if the button is used on a report it returns to the report but if used on a form in a tab it returns to that tab?  Side note: Why doesn't QuickBase just always return to the tab you were on in a form by default when you save or in reload?

AdamKeever1
Forum|alt.badge.img+2
  • Qrew Commander
  • Mar 1, 2018 9:49 PM UTC
Insightful. Thank you Dan.

  • Qrew Corporal
  • Mar 1, 2018 10:02 PM UTC
>Side note: Why doesn't QuickBase just always return to the tab you were on in a form by default when you save or in reload?

For every user that wants one behavior there will be a dozen others that want some other behavior. The feature you want may be so microscopic that it never floats to the top of QuickBase's feature list.  This is especially true if the feature is cosmetic, has a workaround or more importantly isn't viewed  as a distinguishing product feature that will drive revenue.

But your need is real and this is why QuickBase needs to give more attention to implement reasonable default behavior but provide a way to customize behavior for individual users. Today everyone is a snowflake and wants specific product features. Marketing has to realize that the  area at the head of the demand curve is almost equal the area in the tail of the demand curve. The rules have changed.