SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2014
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to render an array as radio buttons

    Hi,
    I have a form like below, in which form fields are in an array.

    HTML Code:
    <form id="submit" method="post">
                    <div data-bind="foreach: participants" id="partifield">
                        <p style="font-weight:bold;color:#039;" data-bind="text: 'Participant ' + NoPrticiField"></p><br/>
                        <b>Full name:</b><input name="empname" id="empname" data-bind="value: empname"><br/>
                        <b>Designation :</b><input name="designation" id="designation" type="text" data-bind="value: designation"><br/>
                        <b> Email :</b><input name="email" id="email" type="text" data-bind="value: email"><br/>
                        <div>
                         <b><input name="option" id="option" type="radio" data-bind="    value: optionCount">
                        </div>
                    </div>
                    <div>
                        <input name="firstN" id="firstN"  data-bind="value: firstN ">
                 <input name="lastN" id="lastN"  data-bind="value: lastN">
                 <input name="orgN" id="orgN"  data-bind="value: orgN">
                        <div class="button"   data-bind="dxButton: { text: 'Click me', clickAction: processClick }"></div>
                    </div>
                </form>
    Code:
                var selectPartiNo = 2;
                var i = 4
                 
    
                var participants = [];
                var optionArray = new Array();
                 
                for (var NoPrticiField = 1; NoPrticiField <= selectPartiNo; NoPrticiField++) {
                   
                   optionArray[NoPrticiField] = new Array();
                 
                   
                   for (x = 1; x <= i; x++) {
                     
                     
                        optionArray[NoPrticiField].push(x);
                        //alert(x);
    
                    };
    
                        participants.push({
                        NoPrticiField: NoPrticiField,
                        empname: ko.observable(),
                        designation: ko.observable(),
                        email: ko.observable(),
                        optionCount:optionArray[NoPrticiField].push(x),
                       
                    });
                   
                }
               
    
                viewModel.participants(participants);
    I need the to repeat the radio buttons " var i " times for each participant, Like the below picture..

    https://lh4.googleusercontent.com/-o...ted+Result.jpg

    Currently i have like this
    https://lh6.googleusercontent.com/-q...entPicture.jpg

    Any help will be greatly appreciated... Thanks in advance...

  2. #2
    SitePoint Enthusiast bronze trophy \\.\'s Avatar
    Join Date
    Oct 2013
    Location
    UK
    Posts
    72
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This I feel is a framework / library issue that would be better off discussed on the vendors web forum for helping you unless someone here has experience in using knockout.js


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •