how to check if user selected radio button and insert radio button value into another list

May 1, 2014 at 12:49 AM
Edited May 1, 2014 at 8:35 PM
I can only select 1 radio button in the whole form
, but i want to select each radio button (answer ) for each question
and then insert that into a list along with the current user

<script language="javascript" type="text/javascript" src="http://itlab1/ca/Scripts/jquery11.js"></script>
<script language="javascript" type="text/javascript" src="http://itlab1/ca/Scripts/jquery.SPServices-2014.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready(function() { 

    GetQuestions();
    
    $("#SubmitAnswers").click(function() {
          
         alert(" inside submit"); 
         // get logged in  user name
         //var currentuser =
         
         // 
        
        
    });
    
    
    

});
    
    
    function GetQuestions()
    {
    
        alert("jQuery");
        alert($().SPServices.SPGetCurrentSite());
        
         //The display name of the list we are reading data from
        var list = "Questions";
        
        
        var queryStringVals = $().SPServices.SPGetQueryString();
        var quizID = queryStringVals["varname"];
        alert(quizID);
        
        
        var fieldsToRead =     "<ViewFields>" +
                                "<FieldRef Name='Title' />" +
                                "<FieldRef Name='Description' />" +
                               "</ViewFields>";
        
        var query = "<Query>" +
                        "<Where>" +
                         "<Eq>" + 
                                "<FieldRef Name='Quiz' /><Value Type='Text'>" + quizID + "</Value>" +
                            "</Eq>" +
                            
                        
                            "<Neq>" +
                                "<FieldRef Name='ID'/><Value Type='Number'>0</Value>" + 
                            "</Neq>" +
                        "</Where>" +
                        "<OrderBy>" + 
                            "<FieldRef Name='Title'/>" +
                        "</OrderBy>" +
                    "</Query>";
        
        
         
                    
                     var method = "GetListItems";                 
                    var webURL =  $().SPServices.SPGetCurrentSite() ;                     
                    var list = "Questions";                      
                    var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' />" +"</ViewFields>";
                //  var query = "<Query><OrderBy><FieldRef Name='ID'  Ascending='True' /></OrderBy></Query>";
                //  var query = "<Query><Where><Eq><FieldRef Name="Title" /><Value Type="Text">title asp.net</Value></Eq></Where></Query>";
                    
                    
                    $().SPServices({
                        operation: method,
                        async: false, 
                        webURL: webURL,
                        listName: list,
                        CAMLViewFields: "<ViewFields Properties='True' />",
                        CAMLQuery: query,                                                                                     
                        completefunc: function (xData, Status)
                         {
                             $(xData.responseXML).SPFilterNode("z:row").each(function() 
                             {
                                  var ID = $(this).attr("ows_ID");
                                  var title = $(this).attr("ows_Title");
                                  var questionNumber = $(this).attr("ows_QuestionNumber");
                                  var question = $(this).attr("ows_Question");
                                  var answera =  $(this).attr("ows_AnswerA");
                                  var answerb = $(this).attr("ows_AnswerB");
                                  var answerc = $(this).attr("ows_AnswerC");
                                  var answerd = $(this).attr("ows_AnswerD");
                                  
                                   $("#myDataTable").append("<tr align='middle'>" +
                                   "<td align='left'>Question Number  "+ questionNumber+"</td></tr><tr>" + 
                                   "<td align='left'>"+ question+"</td></tr><tr>" + 
                                   
                                   
                                   "<td align='left'>"+ answera+"</td></tr><tr>" + 
                                   "<td align='left'>"+ answerb+"</td></tr><tr>" + 
                                   "<td align='left'>"+ answerc+"</td></tr><tr>" + 
                                   "<td align='left'>"+ answerd+"</td></tr><tr>" + 
                                     
                                   "<td align='left'><input type='radio' name='rbanswer' value='a'>a</td></tr><tr>" + 
                                    "<td align='left'><input type='radio' name='rbanswer' value='b'>b</td></tr><tr>" +
                                   "<td align='left'><input type='radio' name='rbanswer' value='c'>c</td></tr><tr>" + 
                                    "<td align='left'><input type='radio' name='rbanswer' value='d'>d</td></tr><tr>" +
                                    "<td align='left'></td></tr><tr>" +
                                    "<td align='left'></td>" +                                  
                                    
                                   "</tr><br><p>");
                               });
                       }
           });
                    
            
    
        
    }
    
    

</script>

<body>
<table id="myDataTable" border =1 width="95%" align="center">
                        <tr bgcolor="lightBlue">
                                    
                        <td><B>Quiz</B></td>
                        
                        </tr>
 </table>
 
    <input name="SubmitAnswers" id="SubmitAnswers" type="button" value="Submit" style="height: 21px; width: 50px">
 
 </body>

May 2, 2014 at 2:52 PM
If you are only able to select one radio button in the entire form it's likely they all have the same 'name' attribute. That's how the DOM groups radio buttons together (not an SPServices issue).

Geoff