logo
down
shadow

Populate select list using javascript


Populate select list using javascript

Content Index :

Populate select list using javascript
Tag : javascript , By : user183526
Date : November 24 2020, 05:47 AM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

JQGrid Edit mode: how to populate a select list based on selection in a different select list


Tag : asp.net-mvc-3 , By : user171555
Date : March 29 2020, 07:55 AM
it fixes the issue I have a jqGrid that when I go into edit mode I need to have 2 select lists. I need the second list to filter based on the selection from select list 1.
// Set up the jquery grid
    $("#jqTable").jqGrid({
        // Ajax related configurations
        url: '@Url.Action("_CustomBinding")',
        datatype: "json",
        mtype: "POST",
        postData: {
            programID: function () { return $("#ProgramID option:selected").val(); },
            buildID: function () { return $('#Builds option:selected').val(); }
        },
        // Specify the column names
        colNames: ["Assembly ID", "Assembly Type", "Assembly Name", "Cost", "Order", "Budget Report", "Partner Request", "Display"],

        // Configure the columns
        colModel: [
        {name: "AssemblyID", key: true, index: "AssemblyID", width: 40, align: "left", editable: false },
        { name: "AssemblyTypeName", index: "AssemblyTypeName", width: 100, align: "left", editable: true, edittype: 'select',
            editoptions: {
                dataUrl: '@Url.Action("_AssemblyTypes")',
                buildSelect: function (data) {
                    jqGridAssemblyTypes = jQuery.parseJSON(data);
                    var s = '<select>';
                    if (jqGridAssemblyTypes && jqGridAssemblyTypes.length) {
                        for (var i = 0, l = jqGridAssemblyTypes.length; i < l; i++) {
                            var ri = jqGridAssemblyTypes[i];
                            s += '<option value="' + ri + '">' + ri + '</option>';
                        }
                    }
                    return s + "</select>";
                },
                dataInit: function (elem) {
                    var AssemblyTypes = $(elem).val();
                    $("#jqTable").setColProp('AssemblyName', { editOptions: { dataUrl: '@Url.Action("Assemblies", "Build")' + '/' + AssemblyTypes} });
                },
                dataEvents: [
                {
                    type: 'change',
                    fn: function (e) {
                        var AssemblyType = $(e.target).val();

                        $.ajax({
                            url: '_JQGridAssemblies',
                            data: { AssemblyTypes: AssemblyType },
                            dataType: 'json',
                            async: false,
                            success: function (assemblies) {
                                jqGridAssemblies = assemblies;
                            }
                        });

                        resetAssemblyValues();

                        // build 'AssemblyName' options based on the selected 'AssemblyType' value
                        var sc = jqGridAssemblies;
                        var newOptions = '';
                        for (var assemblyName in sc) {
                            if (sc.hasOwnProperty(assemblyName)) {
                                newOptions += '<option role="option" value="' +
                                              jqGridAssemblies[assemblyName] + '">' +
                                              jqGridAssemblies[assemblyName] + '</option>';
                            }
                        }

                        // populate the new
                        if ($(e.target).is('.FormElement')) {
                            // form editing
                            var form = $(e.target).closest('form.FormGrid');
                            $("select#AssemblyName.FormElement", form[0]).html(newOptions);
                        }

                    }
                }
            ]

            }
        },
        { name: "AssemblyName", index: "AssemblyName", width: 100, align: "left", editable: true, edittype: 'select',
            editoptions: {
                dataUrl: '@Url.Action("_Assemblies")',
                buildSelect: function (data) {
                    var response = jQuery.parseJSON(data);
                    var s = '<select>';
                    if (response && response.length) {
                        for (var i = 0, l = response.length; i < l; i++) {
                            var ri = response[i];
                            s += '<option value="' + ri + '">' + ri + '</option>';
                        }
                    }
                    return s + "</select>";
                }
            }
        },
        { name: "AssemblyCost", index: "AssemblyCost", width: 50, align: "left", formatter: "currency", editable: true },
        { name: "AssemblyOrder", index: "AssemblyOrder", width: 50, align: "left", editable: true },
        { name: "AddToBudgetReport", index: "AddToBudgetReport", width: 100, align: "center", formatter: "checkbox", editable: true, edittype: 'checkbox' },
        { name: "AddToPartnerRequest", index: "AddToPartnerRequest", width: 100, align: "center", formatter: "checkbox", editable: true, edittype: 'checkbox' },
        { name: "Show", index: "Show", width: 50, align: "center", formatter: "checkbox", editable: true, edittype: 'checkbox'}],

        // Grid total width and height and formatting
        //width: 650,
        //height: 220,
        altrows: true,

        // Paging
        //toppager: true,
        pager: $("#jqTablePager"),
        rowNum: 10,
        rowList: [10, 20, 50, 100],
        viewrecords: true, // Specify if "total number of records" is displayed
        emptyrecords: 'No records to display',

        // Default sorting
        sortname: "AssemblyID",
        sortorder: "asc",

        // Grid caption
        caption: "Build Template",

        // grid command functionality
        editurl: '@Url.Action("_AjaxUpdate")'
    }).navGrid("#jqTablePager",
        { refresh: false, add: true, edit: true, del: true },
            {
                url: '@Url.Action("_AjaxUpdate")',
                editData: {
                    extraParam: function (params, postdata) {
                        programID = $("#ProgramID option:selected").val();
                        buildID = $('#Builds option:selected').val();
                        startDate = $('#DateBegin').val();
                        endDate = $('#DateEnd').val();
                        return programID + '|' + buildID + '|' + startDate + '|' + endDate;
                    },
                    reloadAfterSubmit: true,
                    closeAfterEdit: true
                }
            }, // settings for edit
            {
                url: '@Url.Action("_AjaxUpdate")',
                addData: {
                    extraParam: function (params, postdata) {
                        programID = $("#ProgramID option:selected").val();
                        buildID = $('#Builds option:selected').val();
                        startDate = $('#DateBegin').val();
                        endDate = $('#DateEnd').val();
                        return programID + '|' + buildID + '|' + startDate + '|' + endDate;
                    },
                    reloadAfterSubmit: true,
                    closeAfterAdd: true
                }
            }, // settings for add
            {
                url: '@Url.Action("_AjaxUpdate")',
                delData: {
                    extraParam: function (params, postdata) {
                        programID = $("#ProgramID option:selected").val();
                        buildID = $('#Builds option:selected').val();
                        startDate = $('#DateBegin').val();
                        endDate = $('#DateEnd').val();
                        return programID + '|' + buildID + '|' + startDate + '|' + endDate;
                    },
                    reloadAfterSubmit: true,
                    closeAfterDelete: true
                }
            }, // settings for delete
            {sopt: ["cn"]} // Search options. Some options can be set on column level
     );

How can I make the selection of a value from a select list populate options in a second select list using AngularJS


Tag : angularjs , By : redha
Date : March 29 2020, 07:55 AM
this one helps. You can watch for changes on a scope variable using $watch and manipulate other parts of app within calback.
$scope.$watch('testAccounts', function(){
  /* get updated values and update other select "model" on success*/
});

how do you populate select list with json data in javascript


Tag : javascript , By : user183345
Date : March 29 2020, 07:55 AM
To fix this issue I am trying to update html select list with json data as shown in this jsfiddle , You need to parse to json:
var jsonData = JSON.parse("[{\"id\":1,\"desc\":\"Date\"},{\"id\":2,\"desc\":\"CPU\"}]");

How to create a select list with javascript and populate it with php sql?


Tag : javascript , By : Robby
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Honestly speaking, I don't think composing a database query inside an HTML page is a good idea. Doing that will disclose information of your database you want not to disclose if you have security at heart.
The best approach is to store the values you want to pass to php into variables or in an array and pass that to PHP. You may choose a classic POST or an AJAX approach, as you please. Have a look at the links below for further information:

How to populate a select list in a Django Template dynamically using Javascript?


Tag : javascript , By : Pepe Araya
Date : March 29 2020, 07:55 AM
help you fix your problem It looks like you are talking about "chained dropdowns feature".
In Django you can do it using django-select2 library easy.
Related Posts Related QUESTIONS :
  • Why several clicks fire for each instance of a Class?
  • cant grab value from div using attr()
  • Make web service not accessible by browser?
  • Select DOM elements within template
  • How to customize angular ui-grid row background color?
  • Binding data in two respective $scope in AngularJS, how?
  • react put some props after import class
  • Variable is distributed among same components
  • switch class in jQuery/JavaScript for active/inactive state
  • How To Track Outbound Clicks Using Javascript
  • How to get total seconds elapsed since the beginning of the month?
  • Protractor: Stale element reference at "browser.wait(EC.visibilityOf(confDial), FIFTY_SECONDS);"
  • Access to an array inside an object
  • Reseting an JavaScript Interval with different value?
  • Learning Angular for the first time - version 2 or 4?
  • Rendering RSS feed (XML) in React with jquery, why do object values parsed from the feed seem empty?
  • Node.js xml2js http.request tag matching
  • applying texture to custom plane geometry in Threejs
  • How do I pass an Event as a function parameter in HTML written inside JavaScript variable?
  • Interface of object parameter with default value and default property
  • Does using try / catch rather than `.catch` observable operator with XHR requests reduce performance?
  • In IE11 background colors not working on printing
  • TypeScript interface signature "(): string"
  • Is synchronous XMLHttpRequest supported in Internet Explorer 10 and 11?
  • Axios function not returning any values with js
  • How to use firestore TIMESTAMP to create time-stamp in JavaScript
  • Instantiate subclass without constructing
  • Outputing a created object in javascript to a server side JSON file
  • Transition the numeric labels in a bar chart
  • createBottomTabNavigator: hide just one tab from the tabBar
  • iife vs simple statement behavior with document.title
  • showDialogPopup Refresh Page after Click
  • Child component does not set the initial value passed from the parent: ReactJS
  • Nodejs javascript added to button not responding
  • Trying to define a promise.all
  • Python GEE to extract featurecollection timeseries from Landsat imageries
  • How to write negative binary number?
  • Unable to set property of individual object
  • Why Named Function Expression itself cannot assign Name to another Value?
  • How to reset scroll position on single page pagination
  • How to scroll to bottom of page, when a new message is sent - Socket.io
  • How to reconstruct audio blob from a base64 encoded String?
  • How to calculate numbers within an array of objects
  • Using JavaScript to change CSS properties of SVG circles for all circles that was not clicked
  • Is there value in propTypeing repeat required properties at every level of nested components?
  • Call function if variable does not exist in a filter
  • localStorage value doesn't get updated automatically
  • React not updating state with setState correctly inside promises
  • Direct native JavaScript or jQuery method to get containing block of an element
  • Dynamic JSON object to Html Table
  • How to send Id and file to same controller?
  • How to Make a jQuery Table Cell(td) clickable to Run a Function?
  • Prevent the duplicate function onchange event jQuery
  • Reactjs Input Upload doesn't return local URL
  • An unexpected 'StartObject' node was found when reading from the JSON reader. A 'PrimitiveValue' node was expected
  • How to filter a JSON Array, with an eventListener input value at keyup
  • How to separate the different properties of filter in css?
  • Why dont work change event of bootstrap input spinner?
  • How to hide overflow text content in react
  • Is there another way to write line 6
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com