-3

Hi i'm not a programmer and i need a javascript code. I want to pass the URL parameter to a hidden form field!

This is what is added to the URL: ?ref_id=ik20284953

So i want to get the REF_ID and get it into a hidden field of a form which i already have.

How exactly can i do it ?

I found some solutions here in the forum but nothing worked for me!

HELP IS MUUUUCH APPRECIATED!

Greetings Matthias

EDIT:

THIS IS MY FORM:

<div id="form-163709-wrapper">
  <form id="ktv2-form-163709" accept-charset="UTF-8" method="post" action="https://www.klick-tipp.com/api/subscriber/signin.html"><input type="hidden" id="FormField_ApiKey" name="apikey" value="3smez1c7gz8ze9db" /><input type="hidden" id="FormField_Digit" name="fields[fieldDigit]" value="" />
    <div class="ktv2-form-element"><label for="FormField_EmailAddress">Ihre E-Mail-Adresse: </label><br /><input type="text" id="FormField_EmailAddress" name="email" value="" size="40" /></div>
    <div class="ktv2-form-element"><label for="FormField_FirstName">Vorname: </label><br /><input type="text" id="FormField_FirstName" name="fields[fieldFirstName]" value="" /></div>
    <div class="ktv2-form-element"><input type="hidden" id="FormField_81808" name="fields[field81808]" value="" /></div><br />
    <div><input type="submit" id="FormSubmit" name="FormSubmit" value="Ihr Button-Text" /></div>
  </form>
</div>
kboul
  • 9,697
  • 5
  • 27
  • 39

2 Answers2

0

You can get the ref_id with the URLSearchParams().get(), then you can inject the value with setAttribute()

var urlParams = new URLSearchParams(window.location.search);
var myParam = urlParams.get('ref_id');
document.getElementById('FormField_81808').setAttribute('value',myParam)
<form>
  <input type="hidden" id="FormField_81808">
</form>
Alvin Theodora
  • 898
  • 1
  • 9
  • 17
0

First you need to parse the query string, you can check this post: Parse query string in JavaScript

And then if you are using jQuery,

$("#FormField_81808").val(parsed_value);

If it is a native javascript that you are using;

document.getElementById("FormField_81808").value = parsed_value;

PS: It is best to put some code when you are trying to get an answer to this type of questions.

arunes
  • 3,329
  • 2
  • 19
  • 31