Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Building Dynamic Select Box

Status
Not open for further replies.

redtoad

Programmer
Jan 28, 2002
51
US
I am trying to create a single select box based on a dynamic array. However, it appears that only the last value in the array is populating the dropdown. Any help would be appreciated. Here is a snippit of the function:

if (questionsArray.questionType == "Drop Down")
{
// output the answers
document.writeln(&quot;<tr><td align='left'><SELECT class='form' name='&quot; + questionsArray.questionEID + &quot;'&quot;);

if (questionsArray.answer1 != &quot;&quot;)
document.writeln(&quot;<option value='Answer 1'>&quot;
+ questionsArray.answer1 + &quot;</option>&quot;);

if (questionsArray.answer2 != &quot;&quot;)
document.writeln(&quot;<option value='Answer 2'>&quot;
+ questionsArray.answer2 + &quot;</option>&quot;);

if (questionsArray.answer3 != &quot;&quot;)
document.writeln(&quot;<option value='Answer 3'>&quot;
+ questionsArray.answer1 + &quot;</option>&quot;);

document.writeln(&quot;</select></td></tr>&quot;);
}
 
if (questionsArray.questionType == &quot;Drop Down&quot;){
newSelect = document.createElement(&quot;select&quot;)
for (x=1; x<3; x++){
answer = eval(&quot;questionsArray.answer&quot; + x)
if (answer != &quot;&quot;){
newOption = document.createElement(&quot;option&quot;)
newOption.text = answer
newOption.value= &quot;Answer &quot; + x
newSelect.appendChild(newOption)
}
}
//you'll need to grab a node to append this
document.getElementById(&quot;formID&quot;).appendChild(newSelect)
}


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top