Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6357509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:10:46+00:00 2026-05-24T23:10:46+00:00

I have a function which builds html controls dynamically with jQuery and Knockout, but

  • 0

I have a function which builds html controls dynamically with jQuery and Knockout, but check and radio buttons don’t work, they are not binding.

function createControls(id, ctrl) {
    var obj = $.parseJSON(ctrl.settings)['es'];
    var validate = obj.validate;
    switch (ctrl.type) {
    case 'PlainText':
        var PlainText = obj.caption + ": " + "<input data-bind='value: ctrid" + ctrlid + "' onChange='javascript:saveValue(" + id + ",this.value)' value='" + obj.value + "'><br>";
        BuildViewModel(obj);
        return PlainText;
        break;

    case 'PasswordEdit':
        var PasswordEdit = obj.caption + ": " + "<input type='password' data-bind='value: ctrid" + ctrlid + "' value='" + obj.value + "'><br>";
        BuildViewModel(obj);
        return PasswordEdit;
        break;

    case 'SingleLineText':
        var single = obj.caption + ": " + "<input data-bind='value: ctrid" + ctrlid + "' name='ctrid" + ctrlid + "'  onChange='javascript:saveValue(" + id + ",this.value)' value='" + obj.value + "' required='" + validate.required + "' ><br>";
        validar(validate);
        BuildViewModel(obj);
        return single;
        break;

    case 'OptionMultiple':
        var array_js = new Array();
        var i = 0;
                    var check = "<div align='left'><br>" +"<label>"+ obj.caption + ": " + "</label>";
                    $.each(obj.items, function (k, v) {
                        check += "<input type='checkbox' value='" + v.value + "'     data-bind='checked: ctrlid" + ctrlid + "'>" + v.value;
                         array_js[i] = v.value;
                        i++
                    });
                    check += "</div>"
      
        BuildViewModelCheck(obj, array_js);
        return check;
        break;
    case 'SingleCombo':
        var array_js = new Array();
        var i = 0;
        var combo = "<div align='left'><br>" + "<label>" + obj.caption + ": " + "</label>";
        combo += "<select name='ctrid" +ctrlid + "' data-bind='options: ctrid" + ctrlid + ",value:select" + ctrlid + "'></select>";
        combo += "</div>";
        $.each(obj.items, function (k, v) {
             array_js[i] = v.value;
            i++

        });
        validar(validate);
        BuildViewModelCombo(obj, array_js);
        return combo;
        break;
    case 'Option':
                    var array_js = new Array();
                    var i = 0;
        var option = "<div align='left'><br>" + "<label>" + obj.caption + ": " + "</label>";
                    $.each(obj.items, function (k, v) {
                        option += "<input type='radio' value='" + v.value + "' data-bind='checked: ctrlid" + ctrlid + "'  name='ctrid" + ctrlid + "'/>" + v.value;
                        array_js[i] = v.value;
                        i++
                    });

        option += "</div>"
        validar(validate);
        BuildViewModelRadio(array_js);
        return option;
        break;
    }

}


function BuildViewModel(obj) {
    var iden = "ctrid" + ctrlid;
    viweModel[iden] = ko.observable(obj.value);
}

function BuildViewModelCheck(obj,array) {
    var iden = "ctrid" + ctrlid;
    viweModel[iden] = ko.observable(true);
    //ko.observableArray(["Esposa", "Hijos"]);
}

function BuildViewModelRadio(aray) {
    var iden = "ctrid" + ctrlid;
    viweModel[iden] = ko.observable(aray);
}

function BuildViewModelCombo(obj, array) {
    var iden = "ctrid" + ctrlid;
    var select= "select" + ctrlid;
    viweModel[iden] = array;
    viweModel[select] = ko.observable();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:10:47+00:00Added an answer on May 24, 2026 at 11:10 pm
    var arrInput = new Array(0);
    var rule = {};
    var messages = {};
    var validator = null;
     viweModel = {};
    
    
    
    
    
    function addControls(ctrl) {
        arrInput = new Array(0);
        arrInput.push(arrInput.length);
        display(ctrl);
    }
    
    function display(ctrl) {
          for (intI = 0; intI < arrInput.length; intI++) {
            document.getElementById('parah').innerHTML += createControls(arrInput[intI], ctrl);
        }
    }
    
    
    function createControls(id, ctrl) {
        var obj = ctrl.settings.es
        var validate = obj.validate;
        console.log(obj.validate);
    
    switch (ctrl.type) {
        case 'Heading':
            return "<div align='left'><br><h3>" + obj.caption + "</h3></br></div>";
            break;
        case 'PlainText':
            var PlainText = obj.caption + ": " + "<input data-bind='value:" + ctrl.name + "' value='" + obj.value + "'><br>";
            BuildViewModel(obj, ctrl);
            return PlainText;
            break;
        case 'PasswordEdit':
            var PasswordEdit = obj.caption + ": " + "<input type='password' data-bind='value:" + ctrl.name + "' value='" + obj.value + "'><br>";
            BuildViewModel(obj, ctrl);
            return PasswordEdit;
            break;
        case 'SingleLineText':
            var single = obj.caption + ": " + "<input data-bind='value:" + ctrl.name + "' name='" + ctrl.name + "' value='" + obj.value + "' required='" + validate.required + "' ><br>";
            validar(validate, ctrl);
            BuildViewModel(obj, ctrl);
            return single;
            break;
        case 'MultiLineText':
            var multi = obj.caption + ": " + "<textarea data-bind='value: " + ctrl.name + "' name='" + ctrl.name + "' value='" + obj.value + "' required='" + validate.required + "'></textarea>";
            validar(validate, ctrl);
            BuildViewModel(obj, ctrl);
            return multi;
            break;
        case 'OptionMultiple':
            var array_js = new Array();
            var i = 0;
                        var check = "<div align='left'><br>" +"<label>"+ obj.caption + ": " + "</label>";
                        $.each(obj.items, function (k, v) {
                            check += "<input type='checkbox' value='" + v.value + "' data-bind='checked: " + ctrl.name + "'/>" + v.value;
                            array_js[i] = v.value;
                            i++
                        });
                        check += "</div>"
                        BuildViewModelCheck(obj, array_js, ctrl);
            return check;
            break;
        case 'SingleCombo':
            var array_js = new Array();
            var i = 0;
            var combo = "<div align='left'><br>" + "<label>" + obj.caption + ": " + "</label>";
            combo += "<select name='" + ctrl.name + "' data-bind='options: " + ctrl.name + ",value:select" + ctrl.name + "'></select>";
            combo += "</div>";
            $.each(obj.items, function (k, v) {
                 array_js[i] = v.value;
                i++
    
            });
            validar(validate, ctrl);
            BuildViewModelCombo(obj, array_js, ctrl);
            return combo;
            break;
        case 'Option':
                        var array_js = new Array();
                        var i = 0;
            var option = "<div align='left'><br>" + "<label>" + obj.caption + ": " + "</label>";
                        $.each(obj.items, function (k, v) {
                            option += "<input type='radio' value='" + v.value + "' data-bind='checked: " + ctrl.name + "'  name='" + ctrl.name + "'/>" + v.value;
                            array_js[i] = v.value;
                            i++
                        });
    
            option += "</div>"
            validar(validate, ctrl);
            BuildViewModelRadio(array_js, ctrl);
            return option;
            break;
    }
    

    }

    function validar(validate, ctrl) {
        if (validate.required) {
            messages[ctrl.name] = { required: validate.message1,
                            regex: validate.message2
            };
                        rule[ctrl.name] = { required: true,
                        regex: validate.regex
                    };
        }
    
        validator  = new jQueryValidatorWrapper("FormToValidate",rule, messages);
    }
    
    
    function BuildViewModel(obj, ctrl) {
    
        viweModel[ctrl.name] = ko.observable(obj.value);
    
    }
    
    function BuildViewModelCheck(obj, array, ctrl) {
    
        viweModel[ctrl.name] = ko.observableArray([]);
    
    }
    
    function BuildViewModelRadio(aray, ctrl) {
    
    
        viweModel[ctrl.name] = ko.observable("");
    }
    
    
    function BuildViewModelCombo(obj, array, ctrl) {
    
    
        var select = "select" + ctrl.name;
        viweModel[ctrl.name] = array;
        viweModel[select] = ko.observable();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP site using MVC, which builds HTML dynamically for most requests.
I have an function which decodes the encoded base64 data in binary data but
I have a function which is a JQuery event handler. Because it is a
I have the following code which builds a JQueryUI Dialog popup. $j('<div></div>') .html(message) .dialog({
I have written a script which dynamically creates a html table based off server
I have a function which parses one string into two strings. In C# I
I have a function which searches an STL container then returns the iterator when
I have a function which gets a key from the user and generates a
i have a function which retrieves values from a webservice , then loops through
I have a function which accepts a string parameter such as: var1=val1 var2=val2 var3='a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.