How do I get the value of id="question_type_' + count + '"?

How do I get the value of id="question_type_' + count + '"?

I'm having some trouble with getting the value of my radio buttons here:  http://testing.feministbitch.com/index.php/quiz_creator. I have the full code at the very bottom.

When you click add question, I made it so that people can choose the following radio buttons: true/false or multiple choice

I'm trying to do this: Based on whether they choose true/false or multiple choice, further radio buttons or inputs+drop downs would come down underneath the question. But i'm failing. Please help me :).

The problem here is that I don't know what to set var x equal to get the true_false value or multiple_choice value. 

I tried, but these didn't work.
  1. //var x = $("#question_type"+count).value;
  2. //var x=document.forms["quizquiz"]["question_type" + count].value;

Here's the part in my code that appends the true/false stuff or multiple stuff based on what radio button they picked: 
  1. if (x=="true_false"){
  2. $('#container').append(
  3. 'The above statement is '+ '<Input id="true_or_false_' + count + '" type = "Radio" Name ="true_or_false[]" value= "true">' + 'True' + '&nbsp;&nbsp;&nbsp;&nbsp;'
  4. + '<Input id="true_or_false_' + count + '" type = "Radio" Name ="true_or_false[]" value= "false">'+ 'False<br /><br/>'
  5. );
  6. }else{
  7. $('#container').append(
  8.       'A: ' + '<input id="multi_choices_' + count + '" name="multiple_choices[]' + '" type="text" maxlength="300" size="150"/><br />' +
  9.       'B: ' + '<input id="multi_choices_' + count + '" name="multiple_choices[]' + '" type="text" maxlength="300" size="150"/><br />' +
  10.       'C: ' + '<input id="multi_choices_' + count + '" name="multiple_choices[]' + '" type="text" maxlength="300" size="150"/><br />' +
  11.       'D: ' + '<input id="multi_choices_' + count + '" name="multiple_choices[]' + '" type="text" maxlength="300" size="150"/><br />' + '<br />'
  12.      +'Correct Choice: '
  13.       +'<select name="correct_choice[]">'
  14.       +'<option value="A">A</option>'
  15.       +'<option value="B">B</option>'
  16.       +'<option value="C">C</option>'
  17.       +'<option value="D">D</option>'
  18.       +'</select>'
  19.       +'<br /><br />'
  20.       );
  21. }

Here's the full code for the page:
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

  5. <title>Quiz Creator</title>
  6. <script type="text/javascript" src="http://testing.feministbitch.com/js/jquery.js"></script>
  7. <script type="text/javascript">
  8. var count = 0;
  9. $(function(){
  10. $('p#add_field').click(function(){
  11. count += 1;
  12. $('#container').append(
  13. '<strong>Question ' + count + '</strong><br />' 
  14. + 'Question text: ' + '<input id="question_field_' + count + '" name="question_fields[]' + '" type="text" maxlength="300" size="150"/><br />'
  15. + '<Input id="question_type_' + count + '" type = "Radio" Name ="questiontype_fields'+count+'[]" value= "true_false">' + 'True/False' + '&nbsp;&nbsp;&nbsp;&nbsp;'
  16. + '<Input id="question_type_' + count + '" type = "Radio" Name ="questiontype_fields'+count+'[]" value= "multiple_choice">'+ 'Multiple Choice<br /><br/>'
  17. );
  18. //var x = $("#question_type"+count).value;
  19. var x=document.forms["quizquiz"]["question_type" + count].value;
  20. var a=3;
  21. alert(a);
  22. if (x=="true_false"){
  23. $('#container').append(
  24. 'The above statement is '+ '<Input id="true_or_false_' + count + '" type = "Radio" Name ="true_or_false[]" value= "true">' + 'True' + '&nbsp;&nbsp;&nbsp;&nbsp;'
  25. + '<Input id="true_or_false_' + count + '" type = "Radio" Name ="true_or_false[]" value= "false">'+ 'False<br /><br/>'
  26. );
  27. }else{
  28. $('#container').append(
  29.       'A: ' + '<input id="multi_choices_' + count + '" name="multiple_choices[]' + '" type="text" maxlength="300" size="150"/><br />' +
  30.       'B: ' + '<input id="multi_choices_' + count + '" name="multiple_choices[]' + '" type="text" maxlength="300" size="150"/><br />' +
  31.       'C: ' + '<input id="multi_choices_' + count + '" name="multiple_choices[]' + '" type="text" maxlength="300" size="150"/><br />' +
  32.       'D: ' + '<input id="multi_choices_' + count + '" name="multiple_choices[]' + '" type="text" maxlength="300" size="150"/><br />' + '<br />'
  33.      +'Correct Choice: '
  34.       +'<select name="correct_choice[]">'
  35.       +'<option value="A">A</option>'
  36.       +'<option value="B">B</option>'
  37.       +'<option value="C">C</option>'
  38.       +'<option value="D">D</option>'
  39.       +'</select>'
  40.       +'<br /><br />'
  41.       
  42.       
  43.       );
  44. }
  45. });
  46. });
  47. </script> 



  48. </head>



  49. <body>



  50. <div id="upload">
  51. <h1>Quiz Creator</h1>

  52.     <?php
  53.     
  54.     $attributes = array('name' => 'quizquiz', 'id' => 'quizquiz');

  55.     echo form_open_multipart('quiz_creator');
  56.     //controller named quiz_creator
  57.     
  58.     ?>
  59.     Quiz Name: <input id="quiz_name" name="quiz_name" type="text" maxlength="100" size="100"/><br /><br />
  60.     <?php

  61. //-------------------------------------------------study guide uploader
  62. for ($i = 1; $i <= 5; $i++) {   
  63. echo 'Study Guide '.$i.': '. form_upload('studyguide'.$i.'') . "<br />";
  64. }
  65. //-------------------------------------------------study guide uploader
  66. echo "<br />";

  67. ?>    
  68.     
  69.     
  70.         <div id="container">
  71.             <p id="add_field"><a href="#"><span>&raquo; Add a Question</span></a></p>
  72.         </div>
  73.         
  74.     
  75.     <br /><br />


  76. <?php
  77. echo "<br /><br />";
  78.     echo form_submit('upload', 'Upload');
  79.     echo form_close();
  80.     ?>

  81.     
  82. </div>



  83.     


  84. </body>



  85. </html>