Search code examples
javascripthtmlhostname

How to fill in VALUE with JS element


I hope this is kinda clear to you all.
I have a form where I add some hidden parameters, I also want to add the hostname in such a field.

<input type="hidden" id="URL" value="www.xxxx.xx" name="URL" />

However, I can get the hostname, for example via this JS:

document.getElementById("URL").innerHTML = 
window.location.hostname;

But in this way I only get it via the ID, which won't work to get it as a value.
Do you have any idea how to get that filled in?

Thanks, Eelco


Solution

  • Add it to the value of the element

    document.getElementById("URL").value = window.location.hostname;