What I'm trying to achieve is to display a different message, based on what option is selected within a form. The message is displayed on a redirect "Thank you" page.
<select name="rsvp" id="rsvp">
<option value="">Select</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
On the redirected page I have the following function:
<script type="text/javascript">
function displayMsg() {
var attendingYes = "Yes";
var attendingNo = "No";
if (document.getElementById('rsvp').value == 'Yes') {
document.write(attendingYes);
}
else {
document.write(attendingNo);
}
window.onload = displayMsg;
}
</script>
Error: Uncaught TypeError: Cannot read property 'value' of null
I added an alert, which did not display, so the function does not run. The reason I added the onload inside the function is that I do not want to edit the templates which affect other pages.
See the mistake?