George Mason University Antonin Scalia Law School

Events Planning Form Using Javascript

A short questionnaire to direct users to the right form using Javscript
window.onload = function() { document.getElementById('link1').style.display = 'none'; document.getElementById('link2').style.display = 'none'; }; //Clears div box

var x, y, z; //assigns variables to radio selections

function a1(answer1){ x = answer1; };
function a2(answer2){ y = answer2; };
function a3(answer3){ z = answer3; };

//if all answers are no, display link2 and hide link2; if any answers are yes, do the opposite.

function showdiv() { if (x==1 | y==1 | z==1){ document.getElementById('link1').style.display='block'; document.getElementById('link2').style.display='none'; } else { console.log("None of the questions is 1"); document.getElementById('link1').style.display='none'; document.getElementById('link2').style.display='block'; } return; }

//How to structure your HTML to code. Onlick assigns value to x,y,z variables

<input type="radio" onclick="a1(1)" name="q1">Yes
<input type="radio" onclick="a1(0)" name="q1">No

//execute code
<button onclick="showdiv()">What Form Do I Need?</button>

//hide show divs using IDs
<div id="link1">
Link 1
<div id="link2">
Link 2