Can't find element RRS feed

  • Question

  • User522790094 posted


    • Windows Server 2012
    • Visual Studio 2015
    • Web Application Project


    I'm using the getElementById function to try to find an element but it's returning null and I've viewed the source and know that the Id I'm passing is correct. Any ideas? The issue occurs in all browsers.


    document.getElementById(idprefix + "hfSignTime_Password").value.length

    Friday, January 19, 2018 8:48 PM

All replies

  • User475983607 posted

    The Id must be incorrect as getelementById() works and has worked for a long long time. 

    Try using the browser's developer tools to verify idprefix is what you expect.   Also from dev tools you can execute code in the console to make sure your code is correct.


    Friday, January 19, 2018 9:11 PM
  • User2103319870 posted

    By any chance are you trying to access the value before the page has been rendered. if so then you could consider wrapping your code like below

    window.onload = function() {
       alert(document.getElementById(idprefix + "hfSignTime_Password").value.length);

    Friday, January 19, 2018 9:29 PM
  • User-1838255255 posted

    Hi jwbutler23113,

    According to your description and code, you say it return null, maybe this issue is related to can't get the element, please use the following code to check the id if correct? 

    var newid = idprefix + "hfSignTime_Password";

    Also you could debug your js code in browser, check the code how to run? 

    If still can't solve it, please share more code for us, this could help you solve the problem. 

    Best Regards,

    Eric Du 

    Monday, January 22, 2018 9:38 AM