I'm trying to figure out how to do something similar. I have a simple form on a 7.1 site and I'd like to auto-populate a coupon code into the "Offer Code" field of the form based on data gleaned from the URL. (Nothing about the codes are secret in any way. This is just a convenience thing.)
I'm able to get the coupon code from the URL (e.g., site.com/form-page?code=12345) into my variable via javascript, but it seems like I'm having trouble selecting the input field and pasting the value of that variable. Here's a snippet of the relevant form HTML:
<div id="64ba7865-b8b9-4e6d-8a30-cb7b00c984d3" class="form-item field text required">
<label class="title" for="64ba7865-b8b9-4e6d-8a30-cb7b00c984d3-field">
Offer Code
<span class="required" aria-hidden="true">*</span>
</label>
<input class="field-element text" type="text" id="64ba7865-b8b9-4e6d-8a30-cb7b00c984d3-field" placeholder="ALG-" aria-required="true">
</div>
Any suggestions? I've tried using querySelector on the input id as well as the class. (It's the first instance of an input with that class, so it should be relatively straightforward.)