Set Input Value via Javascript?

Joshua Myers asked on July 30, 2019 20:03

We have an unsubscribe form with one email input.

In order to keep the PII from passing to Google Analtyics, I'd like to set the link to /unsubscribe#email=test@test.com

Then, via Javascript on the page, I'd like to prefill the field with that email.

My question is: How can we set the value of a bizform text input via Javascript when it has the Watermark on? When I use the following code, it looks like the value gets entered, but it doesn't stick if you put your cursor in the field or when the form is submitted...

document.getElementById('field-id-here').value = 'test@test.com';
document.getElementById('field-id-here').click();

With the K11 Watermark functionality enabled, how do we make the field value stick?

Recent Answers


Cindy Lin answered on July 30, 2019 20:28

I'm interested in this question as well

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on July 31, 2019 13:20 (last edited on July 31, 2019 13:20)

Why don't you use query macro? - you just need to change # to ? in the URL and set {% email %} macro as default value for the form field.

1 votesVote for this answer Mark as a Correct answer

Joshua Myers answered on July 31, 2019 13:46

@Roman Hutnyk, if I use a normal HTTP GET variable, it passed into Google Analytics (and our server logs) and stores PII in both places. As this should only act as a front-side "variable", I am able to avoid that logging in our specific instance.

Regardless of that, the question stands: How do you use Javascript to fill a K11 text input (with a Watermark)?

I also have another instances where we're doing an AJAX lookup from a third-party DB and would like to fill field values with that info too, but it's proving difficult. Outside of K11, it's as simple as setting the input.value attribute, but it's the Watermark functionality that is getting in the way.

0 votesVote for this answer Mark as a Correct answer

Joshua Myers answered on September 5, 2019 17:04 (last edited on October 2, 2019 21:21)

Any other thoughts?

It would be nice to be able to do this in an "official" compacity, but I'm open to workarounds as well!

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.