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!

1
  • 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 (..). Commented Mar 13, 2018 at 1:50

2 Answers 2

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;
}
Sign up to request clarification or add additional context in comments.

4 Comments

Hmm maybe I have it formatted incorrectly but it doesn't seem to be working? <div id="button-test">test string</div> <script type="text/javascript"> var ss_form = {'account': 'X', 'formID': 'X'}; ss_form.width = '100%'; ss_form.height = '500'; ss_form.domain = 'app-X.marketingautomation.services'; ss_form.hidden = {'field_XXXX': 'Test1' }; document.getElementById("button-test").onclick = function(event) { ss_form.hidden.field_XXXXX += ', ' + this.innerHTML; } </script> just returns 'Test1'
looks like your field_XXXXX has +/- too many X's :) ... make sure they are both field_XXXXX (5 X's)
Oh they are the same in the actual code! It's really field_2752132099 I just simplified here.
then there may be some other issue that we're not seeing.
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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.