Make sure that the element exists in DOM before you call your selector. document.ready can be used to wait for the document object to load first. Following snippet works fine:

function getValue() {
  
  docsd = document.getElementById('numbern');
  console.log(docsd.value);

};
document.addEventListener('DOMContentLoaded', getValue(), false);
<input id="numbern" name="nub" placeholder="Your Roll No." class="form-control col-6" value="10" autocomplete="off">

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top