Skip to content

Instantly share code, notes, and snippets.

@dgbrahle
Created July 9, 2010 13:42
Show Gist options
  • Save dgbrahle/469473 to your computer and use it in GitHub Desktop.
Save dgbrahle/469473 to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script language="javascript" type="text/javascript">
function getCount(){
removeAllAnswers();
var answerCount = document.getElementById("jsSelecter").value;
for (var i=0; i < answerCount; i++){
insertAnswer();
};
}
function removeAllAnswers(){
var list = document.getElementById("answer-list");
if(list.hasChildNodes()){
while (list.childNodes.length >= 1){
list.removeChild(list.firstChild);
}
}
}
function insertAnswer(){
var list = document.getElementById("answer-list");
var li = document.createElement("li");
for (var i=1; i<=6;i++) {
var txt = ("Question " + i);
}
var newtext = document.createTextNode(txt);
document.answer-list.appendChild(newtext);
var input = document.createElement("input");
input.id = "1";
input.name = "1";
input.type = "text";
li.appendChild(input);
list.appendChild(li);
}
</script>
</head>
<body>
How many Answers Are needed?
<select id="jsSelecter" onchange="getCount();">
<option selected value="">-</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<br />
<ul id="answer-list">
Question 1<br />
<li><input id="1" name="1" type="text"></li>
Question 2<br />
<li><input id="1" name="1" type="text"></li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment