0

hello guys I'm trying to make a Multipage form in java script but keep receiving the error Uncaught TypeError: Cannot read property 'style' of null; I've searched and found answers but to no avail.... it seems to work fine until I implement the show element function later in the code.

<script type="text/javascript">
document.write('page'+1)

function hideElement(element)
{
 document.getElementById(element).style.display = 'none';
}
function showElement(element)
{
 document.getElementById(element).style.display = 'initial';
}


/*function lastPage()
{ 
  hideElement('page'+i-1);
  showElement('page'+i);
}
*/






</script>
  • It means that `document.getElementById(element)` is returning `null`. That happens when there's no actual element in the DOM matching the given id. – Pointy Feb 08 '15 at 16:20
  • Also, "initial" is not a valid value for the CSS "display" property. – Pointy Feb 08 '15 at 16:21
  • @Pointy [initial](http://www.w3.org/TR/css-values/#common-keywords) is a valid value for every CSS property. – Quentin Feb 08 '15 at 16:22
  • @Quentin yes I just checked; you're right. I haven't used that in many many years I think :) – Pointy Feb 08 '15 at 16:23
  • @Quentin ... maybe it's because it's never worked in IE. – Pointy Feb 08 '15 at 16:30
  • thank you so much for the help , do you know why they would return null if I have the ids page1,page2,page3, and page4 later in my html ? @Quentin – Bill Simmons Feb 08 '15 at 16:47

0 Answers0