Skip to main content
Question

Javascript to find and replace and then update fields

  • March 5, 2019
  • 0 replies
  • 103 views

I have a 2 part issue:

Using the [iol] method, I have a mod.js file and am calling it in my form.

Issue #1:

I am able to retrieve the data in some of the fields using 

var intro = _fid_15.value;

However, using var name = _fid_66.value; does not work.
Upon inspection, there isn't a field with id _fid_66 even though the data is being displayed. There is a label for="_fid_66" with a subsequent div following with the info. The div has an id of "tdf_63" (which I am assuming is the 63rd field on the form as the field next field is tdf_64 and the one after that is tdf_65).

Using getElementById().label does not work as there isn't an element with _fid_66.

We are in constant development right now and there is absolutely no guarantee that the fields will remain in the order they are in (in fact I can 100% assume not).

Question #1:
How do I get the value in this div into a variable without knowing the exact number on the form? 


Issue #2:

Ignoring issue #1, I have changed "var intro" and now want to put the new value back into the field. 

Using "var intro = _fid_15.value;" I then change the value. Then using "_fid_15.value = newValue" and saving the form (via saveAndKeepWorkingMenuOption.click();).

Updated value does not get saved.


Question #2:
What step am I missing to change and save the data?


This topic has been closed for replies.

  • Author
  • Quickbase Alumni
  • March 5, 2019
Want to mention that _fid_15 is a field in the table associated with the form, _fid_66 is a related table field.
Also fields that I will be changing will all be rich-text fields that will also need to be edited later by user.

  • Author
  • Quickbase Alumni
  • March 5, 2019
Field gets changed in form when I run the script straight from load, but it fails when I run the same script in a function.

Forum|alt.badge.img+11
  • Quickbase Staff
  • March 5, 2019
Hi Wendy. What is the goal you are trying to achieve? What is the use case?

  • Author
  • Quickbase Alumni
  • March 5, 2019
Overview:
Template stored in a table with multiple languages and place holders for field values using rich text fields.
Template copied with selected language.
Run script to find and replace place holders with the values for the related case when user clicks a button.

I have everything except pulling in the table field values for the elements without an html element ID of the table field id. 

  • Author
  • Quickbase Alumni
  • March 7, 2019
What is wrong with this formula?

var text thisText = [Body];
$thisText = SearchAndReplace( $thisText, "[PC]", [Case - PC Full Name]);
$thisText