Skip to content

Instantly share code, notes, and snippets.

@byronferguson
Created July 28, 2015 17:30
Show Gist options
  • Save byronferguson/9d7abdb1338bccd46919 to your computer and use it in GitHub Desktop.
Save byronferguson/9d7abdb1338bccd46919 to your computer and use it in GitHub Desktop.
<div class="form-group">
<label for="schoolLevel">Which school are you currently attending?</label>
<select name="schoolLevel" id="schoolLevel" class="form-control">
<option value="0"></option>
<option value="1">High School</option>
<option value="2">Home School</option>
<option value="3">2yr College</option>
<option value="4">4yr College</option>
<option value="5">Other</option>
<option value="6">Not Attending</option>
</select>
</div>
<div id="HSgroup" class="hide"></div>
.
.
.
"use strict";
var $schoolLevel = $('#schoolLevel');
var $HSgroup = $('#HSgroup');
var $homeGroup = $('#homeGroup');
var $collegeGroup = $('#collegeGroup');
var $otherGroup = $('#otherGroup');
var $schoolLevel = $('#schoolLevel');
function showAll() {
$HSgroup.removeClass('hide');
$homeGroup.removeClass('hide');
$collegeGroup.removeClass('hide');
$otherGroup.removeClass('hide');
}
function hideAll() {
$HSgroup.addClass('hide');
$homeGroup.addClass('hide');
$collegeGroup.addClass('hide');
$otherGroup.addClass('hide');
}
$(function() {
$schoolLevel.change(function() {
var selection = $(this).val();
switch(selection) {
case 1:
hideAll();
$HSgroup.removeClass('hide');
break;
case 2:
hideAll();
$homeGroup.removeClass('hide');
break;
case 3:
case 4:
hideAll();
$collegeGroup.removeClass('hide');
break;
case 5:
case 6:
hideAll();
$otherGroup.removeClass('hide');
break;
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment