Set value in a input field with javascript

Hi friends,
I tried myself to set value in a input field by using javascript but it is not working for me. can anyone correct the code.

Incorrect code:

<script type=“text/javascript”>
var a = document.getElementById(“name”);
a.value = “some value”;
</script>

<input type=“text” id=“name”>

Hi there,

The code in itself is correct.
You must just place it after the element that you are trying to manipulate.

<input type="text" id="name">
<script type="text/javascript">
  var a = document.getElementById("name");
  a.value = "some value";
</script>

A best practice is to put all JS at the bottom of the page just before the closing body tag, then you avoid this problem altogether :slight_smile:

Thanks for your reply now it is working.