freelance84 Posted February 17, 2011 Share Posted February 17, 2011 Ok i know i must be something wrong here but i can't see it. I want to check if an id exists before carrying out an action. Here's my if statement: if (document.getElementById("hiddenValues")) The script isn't working if the id isn't on the page. I take it this isn't the correct way to determine if an element exists... what is? (ie simply says "Object Required") Link to comment https://forums.phpfreaks.com/topic/228005-how-to-search-for-an-id/ Share on other sites More sharing options...
jcanker Posted February 18, 2011 Share Posted February 18, 2011 It returns null if the object doesn't exist, and you can't get a value from a null object. Here's a quick workaround: http://bytes.com/topic/javascript/answers/150343-getelementbyid-object-required-error Link to comment https://forums.phpfreaks.com/topic/228005-how-to-search-for-an-id/#findComment-1175948 Share on other sites More sharing options...
freelance84 Posted February 18, 2011 Author Share Posted February 18, 2011 Gracias! Link to comment https://forums.phpfreaks.com/topic/228005-how-to-search-for-an-id/#findComment-1176122 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.