Created
April 2, 2015 08:37
-
-
Save varmais/2a23eb6c5667cb73957d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var showIndex = 0; | |
var titles = document.querySelectorAll('.kysymys'); | |
var questions = document.querySelectorAll('.kysymys + p'); | |
var submit = document.querySelectorAll('button[type="submit"]')[0]; | |
function hideElement (element) { | |
if (!element) { | |
return; | |
} | |
element.style.display = 'none'; | |
} | |
function showElement (element) { | |
if (!element) { | |
return; | |
} | |
element.style.display = ''; | |
} | |
hideElement(submit); | |
for (var i = 0; i < titles.length; i++) { | |
if (i != showIndex) | |
hideElement(titles[i]); | |
} | |
for (var i = 0; i < questions.length; i++) { | |
if (i != showIndex) | |
hideElement(questions[i]); | |
questions[i].addEventListener('click', function (event) { | |
if (!event.target && event.target.nodeName !== 'INPUT') { | |
return; | |
} | |
if (event.target.parentElement !== questions[showIndex]) { | |
return; | |
} | |
showIndex++; | |
if (showIndex === titles.length) { | |
showElement(submit); | |
} else { | |
showElement(titles[showIndex]); | |
showElement(questions[showIndex]); | |
} | |
}); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment