0

I'm using a form that needs to pass a hidden field:

<script type="text/javascript">
    var ss_form = {'account': 'XXXXX', 'formID': 'XXXXX'};
    ss_form.width = '100%';
    ss_form.height = '500';
    ss_form.domain = 'app-XXXXX.marketingautomation.services';
    ss_form.hidden = {'field_XXXXX': 'test item, another item' }; 
</script>

All it needs to be is a comma separated list, but I'm trying to dynamically add comma separated items using external buttons, for example clicking:

<button>add this string</button>

would make it

ss_form.hidden = {'field_XXXXX': 'test item, another item, add this string' }; 

I've tried using append to a div and then using innerHTML as a variable but it's just passing the initial div content from page load rather than the dynamically added items as well. JS is not my strong suit... any help is very much appreciated. Thank you!

user8792133
  • 27
  • 1
  • 8
  • Have you tried to concatenate the values? The conactenacion is a process in which two or more values are joined by an operator, commonly more (+) or two points (..). – Héctor M. Mar 13 '18 at 01:50

2 Answers2

1

Looks like you want something like this:

<button id="button">add this string</button>

document.getElementById("button").onclick = function(event) {
  ss_form.hidden.field_XXXXX += ' ' + this.innerHTML;
}
achendrick
  • 190
  • 1
  • 8
  • Hmm maybe I have it formatted incorrectly but it doesn't seem to be working?
    test string
    just returns 'Test1'
    – user8792133 Mar 13 '18 at 01:55
  • looks like your field_XXXXX has +/- too many X's :) ... make sure they are both field_XXXXX (5 X's) – achendrick Mar 13 '18 at 02:01
  • Oh they are the same in the actual code! It's really field_2752132099 I just simplified here. – user8792133 Mar 13 '18 at 02:03
  • then there may be some other issue that we're not seeing. – achendrick Mar 13 '18 at 02:09
0

Have you tried to concatenate the values? The conactenacion is a process in which two or more values are joined by an operator, commonly more (+) or two points (..).

Try this way

<button id="btn">add this string</button>

<script>
document.getElementById ("btn").onclick = function (event) {
   ss_form.hidden.field_XXXXX + = this.innerHTML + ', '; //Add separated comma values
}
</script>
Héctor M.
  • 2,302
  • 4
  • 17
  • 35