assign value from mysql to radio button inside javascript

Discussion in 'JavaScript' started by Hemant Agarwal, Oct 31, 2010.

  1. #1
    Hi,
    I am developing a quiz system.The loop in the code below prints a question,questions[0] and two options for each question,questions[1] and questions[2].questions is a 2-d javascript array.The problem is that when I select one of the 2 answer choices and post it to a php page and echo it ,the value that is echoed is questions["


    Why is this happening?Thanks

    
    <script type="text/javascript">
    var j;
    for(var i=1;i<=5;++i)
    {
    j=i-1;
    document.write("<div id=\"question" + i.toString() + "\" class=\"text\">");
    document.write("<script>document.write(questions[" + j.toString() + "][0]);<\/script>");
    document.write("<br>");
    
    
    [B]document.write('<input type="radio" name="q' + i +'"  value='questions[" + j.toString() + "][1]' >');[/B]
    document.write("<script>document.write(questions[" + j.toString() + "][1]);<\/script>");
    
    [B]document.write('<input type="radio" name="q' + i +'"  value='questions[" + j.toString() + "][2]' >');[/B]
    document.write("<script>document.write(questions[" + j.toString() + "][2]);<\/script>");
    
    document.write("<br>");
    
    
    document.write("</div>");
    }
    </script>
    
    Code (markup):
     
    Hemant Agarwal, Oct 31, 2010 IP
  2. Hemant Agarwal

    Hemant Agarwal Member

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    31
    #2
    Any ideas,anyone?
     
    Hemant Agarwal, Nov 2, 2010 IP