I'm writing an HTML page for a class project. It needs to show different information based on what the user has selected. I have 5 buttons at the top with onclick
that activates a function that should be changing the text inside of the <p>
element below them.
I tried switching document.GetElementById('main').innerHTML = link;
with alert('link')
, and it gave me an empty alert box. I've checked my syntax repeatedly, and the case statement has no errors in it. I know that it isn't an error in the button element or the function itself, because it did give me an empty alert box when I tried the alert
statement I mentioned earlier. So I've ruled out every error I can think of.
Below is the code (with most button elements and case statements removed for brevity)
<script>
var link = '';
function TextSwitch(n) {
switch (n) {
case '1':{
link = 'Option 1 has been selected'
break;
}
}
document.GetElementById('main').innerHTML = link;
}
</script>
</head>
<body style='background:#ffffee'>
<div align='center'>
<button type=button style='width:10%' onclick='TextSwitch(1)'>Option 1</button>
</div>
<p id='main'>text
</p>