I'm using VB.Net and Javascript is Visual Studio 2010.
I have a webpage that has several <div> elements. I have made these elements into server-side controls by adding the runat="server" attribute. Each of these <div> elements contains data that is displayed based on a menu selection. My problem is that I'm not sure if I'm coding my javascript statements correctly because I keep getting an error message (Error: 'document.getElementById(...)' is null or not an object)when I click on the menu item. When a menu item is clicked, the below javascript function is executed and the error occurs in each one of the case branches depending on which menu item was selected.
The "divID" parameter is actually the ID of each <div> element.
function OpenSection(divID) {
switch (divID) {
case 'SummarySection_DIV':
document.getElementById('SummarySection_DIV').visible = true;
break;
case 'WorkHistory_DIV':
document.getElementById('WorkHistory_DIV').visible = true;
break;
case 'SkillSets_DIV':
document.getElementById('SkillSets_DIV').visible = true;
break;
case 'Education_DIV':
document.getElementById('Education_DIV').visible = true;
break;
case 'ContactMe_DIV':
document.getElementById('ContactMe_DIV').visible = true;
break;
case 'PrintMe_DIV':
document.getElementById('PrintMe_DIV').visible = true;
break;
}
}
I have a webpage that has several <div> elements. I have made these elements into server-side controls by adding the runat="server" attribute. Each of these <div> elements contains data that is displayed based on a menu selection. My problem is that I'm not sure if I'm coding my javascript statements correctly because I keep getting an error message (Error: 'document.getElementById(...)' is null or not an object)when I click on the menu item. When a menu item is clicked, the below javascript function is executed and the error occurs in each one of the case branches depending on which menu item was selected.
The "divID" parameter is actually the ID of each <div> element.
function OpenSection(divID) {
switch (divID) {
case 'SummarySection_DIV':
document.getElementById('SummarySection_DIV').visible = true;
break;
case 'WorkHistory_DIV':
document.getElementById('WorkHistory_DIV').visible = true;
break;
case 'SkillSets_DIV':
document.getElementById('SkillSets_DIV').visible = true;
break;
case 'Education_DIV':
document.getElementById('Education_DIV').visible = true;
break;
case 'ContactMe_DIV':
document.getElementById('ContactMe_DIV').visible = true;
break;
case 'PrintMe_DIV':
document.getElementById('PrintMe_DIV').visible = true;
break;
}
}