Am I implementing the Vue.JS onChange function correctly?

After selecting an option from mod_accs_Role_ID, how can I display the corresponding data stored in the database based on that selection? For example, if I select 1 in mod_accs_Role_ID, then the role_Name 'Hello' should be displayed.

<div class="col-sm-6 form-group">
  <label for="mod_accs_Role_ID" class="col-form-label">Role
   <span class="text-danger">*</span>
  </label>
  
  <select class="form-control" name="mod_accs_Role_ID" v-model="selected" v-on:change="onChange">
    <option value="">Select Role</option>
    <option v-for="item in sel_role" :value="item.role_id">{{item.role_Display}}</option>
   </select>
 </div>

 <div class="col-sm-6 form-group">
    <label for="role_Name" class="col-form-label">Role Action
      <span class="text-danger">*</span>
    </label>

  <select class="form-control not-editable" name="role_Name" disabled>{{selected}}</select>
</div>

JS

  var vm = new Vue({

            el: '#maint_module_ctrl',
            data: {
                list_MyInfo: [],
                sel_role: [],
                selected:""
            },
            created: function () {
                this.doList();
            },
            mounted: function () {
                $(".bt-table").bootstrapTable();


                var dropdownMenu;
                $('.bt-table').on('show.bs.dropdown', function (e) {
                    dropdownMenu = $(e.target).find('.dropdown-menu');
                    $('body').append(dropdownMenu.detach());
                    var eOffset = $(e.target).offset();
                    dropdownMenu.css({
                        'display': 'block',
                        'top': eOffset.top + $(e.target).outerHeight(),
                        'left': eOffset.left
                    });
                });
                $('.bt-table').on('hide.bs.dropdown', function (e) {
                    $(e.target).append(dropdownMenu.detach());
                    dropdownMenu.hide();
                });



            },
            methods: {

                onChange: function () {
                    var self = this
                    ajaxJsonProcess("get", apiPath + "/param/role-dropdown", "", function (inDat) {
                        self.sel_role = inDat;
                    }, dftError);
                },

The On Change function is not receiving any value

Answer №1

Make sure to bind the drop-down menu during the creation of the component's lifecycle hook. Once the @OnChange event is triggered, you will receive the ID of the selected option. You can then use this ID to retrieve the name of the selected item.

let selectName = self.sel_role.filter(role => role.role_id.(selected) !== -1).role_Display;

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Can someone provide guidance on extracting the ID from a JSON value and storing it in a

Hey there, I have come across this jQuery code snippet: var fbuid = zuck; var fbjson = $.getJSON("https://graph.facebook.com/"+fbuid); I am wondering how to extract the id directly from the JSON response into a variable : { id: "4", first_name: "Mark", ...

The getUserMedia() function fails to work properly when being loaded through an Ajax request

When the script navigator.getUserMedia() is executed through regular browser loading (not ajax), it works perfectly: <script> if(navigator.getUserMedia) { navigator.getUserMedia({audio: true}, startUserMedia, function(e) { __ ...

Encountering a problem while trying to launch the development server for a React application using the npm-start

I followed the steps to create a react application using npx create-react-app myapp, but when I use npm start, it fails to start a developer server. Even after trying to reinstall the node_modules, the issue persists. I am using the latest versions of Reac ...

*NgFor toggle visibility of specific item

Here is a snippet of HTML code that I'm working with: <!-- Toggle show hide --> <ng-container *ngFor="let plateValue of plateValues; let i=index"> <button (click)="toggle(plateValue)">{{i}}. {{ btnText }}</button> ...

Vanishing ShareThis Link After Postback in JavaScript

On my webpage at , I have included a ShareThis link in the footer that is generated via Javascript. However, whenever there is an AJAX postback after entering an email on the site, the link disappears. Is there a way to prevent this from happening and ensu ...

When the button is clicked, a modal will pop up

Looking for help in incorporating JavaScript to create a responsive modal that pops up with lyrics when a button is pressed in a table. Any assistance would be greatly appreciated. Note: Only the code for the table has been provided. Let me know if you&ap ...

ng-click="showInventory()" onClick="currentTemplate='/inventory.html'" Not

I'm facing an issue with my menu list. When I apply the ng-repeat directive, it seems to not work properly. However, when I remove the ng-repeat, everything functions as expected. <div class="reports_header_tabs_holder"> <span ng-repea ...

AngularJS $scope variable issue

After searching online, I found this code snippet that I tried to implement, but unfortunately, it's not displaying any data. Below is the HTML code: <html data-ng-app=""> <head> <title>Example 4: Using AngularJS Directives an ...

Child object referencing in JavaScript

As I delved into testing Javascript, a curiosity arose regarding the interaction between child and parent objects. Would the parent object dynamically update to reflect changes in the child object's value, or would it remain static at the initial stat ...

Setting up an Express route for updating data

I am in the process of developing a MEVN stack CRUD application (Vue, Node, Express, MongoDB). I am currently working on setting up an Express route for handling updates in my app... postRoutes.post('/update/:id', async(req, res)=> { cons ...

Storing text entered into a textarea using PHP

In a PHP page, I have a textarea and I want to save its content on click of a save button. The insert queries are in another PHP page. How can I save the content without refreshing the page? My initial thought was using Ajax, but I am unsure if it is saf ...

"Revolutionary AJAX-enabled PHP social commenting system with multi-form support

Why is it that when I submit forms using these ajax functions in PHP, they only send to the first form on the page? I have multiple forms under each article and I want them to be submitted separately. What am I doing wrong? ...

Navigate directly to a child component in Vue, even when the parent component has a parameter

Recently, I have been delving into the world of Vue with TypeScript and I must admit, it has been quite an awesome experience so far. However, as I started learning about Vue routing, a question popped up in my mind that I just can't seem to find a sa ...

Get the latest html content and save it as a .html file using javascript or jQuery

Looking for a way to save an HTML page as a .html file? Having some trouble with jQuery modifications not being included in the exported file? Check out the code snippet below and let me know if you can spot what's going wrong! I'm still getting ...

My JavaScript/jQuery code isn't functioning properly - is there a restriction on the number of api calls that can be made on

Below is the code I have implemented from jquery ui tabs: <script> $(function(){ // Tabs $('#tabs1').tabs(); $('#tabs2').tabs(); $('#tabs3').tabs(); //hover states on the sta ...

Switch Focus and Collapse Submenus upon Menu Click in Recursive React Menu

I've created a dynamic menu system in React using Material-UI that supports recursion for submenus. I'm aiming to implement the following features: 1. When a menu item is clicked, all other open submenus should close and focus on the clicked men ...

Angular checkboxes not triggering ng-click event

Within my Angular application, there is a form that includes checkbox inputs: <div ng-repeat="partner in type.partners"> <label class="checkbox-inline"> <input type="checkbox" value="partner" ng-checked="report.participa ...

The JavaScript library known as Microsoft JScript Angular is not recognized

While integrating Angular into my .Net MVC website, I keep running into a runtime error that reads as follows: 0x800a1391 - Microsoft JScript Runtime Error: 'angular' is undefined. This essentially means that the 'angular' object ...

What could be causing the malfunction of this Ajax conditional dialog?

Can anyone help me troubleshoot this code? I've been trying to fix it for a while now, making multiple changes, but still can't find the solution. If you have any ideas please let me know, I haven't seen any errors in the console. The fir ...

Efficient method to access two arrays simultaneously and combine them into an associative array in JavaScript

When using Ajax to return a table, you have the option of separating column names and row values. Here are two ways to do it: let columns = ["col1", "col2", "col3"]; let rows = [ ["row 1 col 1", "row 1 col 2", "row 1 col 3"] , ["row 2 col 1", "r ...