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

Transferring a File within a Local Network

Operating a web application but encountering issues in transferring files between two PCs on the network. PC A is located at 192.168.1.200 and PC B at 192.168.1.201. The current code functions properly for a single PC setup, however fails to work across ...

Guide to building a JavaScript array and storing data from a separate array into the newly created array in JavaScript

Can you help me create a JavaScript array and save another array of data to be part of the newly created array in JavaScript? I attempted it using the code below. Code: var vvv=this.new_products.length-this.quote.lines.length; let mmm={}; if(v ...

Backand - How can I display the contents of variables using console.log() within Security Actions?

Is there a way to utilize console.log() in Backand, specifically within the server side functions like those found under Security & Auth > Security Actions? I have checked the Read.me which suggests using 'console.log(object) and console.error(obje ...

Making an asynchronous request using Ajax to verify the status of a checkbox

I have two checkboxes, and I want to make an ajax call to a jsp page when one of the checkboxes is clicked. The jsp page should display a table with data fetched from a database. The issue arises when dealing with two checkboxes: <div class="search-in ...

Electron and React: Alert - Exceeded MaxListenersWarning: Potential memory leak detected in EventEmitter. [EventEmitter] has 21 updateDeviceList listeners added to it

I've been tirelessly searching to understand the root cause of this issue, and I believe I'm getting closer to unraveling the mystery. My method involves using USB detection to track the connection of USB devices: usbDetect.on('add', () ...

Unlock the secrets of accessing the router prop in VUE

I have set up a route where I am passing a prop to display different headers in my index component, but I'm struggling to access the prop properly... { path: '/store/:id', name: 'store', component: SystemStart, pr ...

Unable to display exception message as Exception.ToString() function encountered an error

While attempting to connect to a MySql database, I encountered an error message: An error occurred when trying to print the exception string using Exception.ToString() using System; using MySql.Data.MySqlClient; namespace ConsoleApplication1 { class ...

Problem with image title in jQuery mobile

My code seems to be having an issue where the title does not display completely when hovering over it. For example, if the title is set as "The Value", only "The" is shown and not "The Value". Can anyone help me identify the mistake? Thank you in advance ...

When hovering over items in the navigation bar, the entire bar expands seamlessly

I've spent countless hours trying to troubleshoot an issue with my dropdown menu that expands whenever I hover over it. The bar stretches out to accommodate the list of dropdown contents and then reverts back to normal when I move my cursor away. My a ...

Transferring a dynamic HTML file created using R's animation package onto a WordPress platform

After using the animation package in R to create an HTML file, I'm facing some challenges uploading it to my WordPress blog. It appears that additional js or css files may be required for proper functionality, but I'm uncertain about the process. ...

Position items within the dynamically generated div without appending them

Utilizing JavaScript, I dynamically generate a line but struggle to position two balls at both the 1/3 mark from the beginning and end. For reference, please view the image below. I aim to have two balls appear upon pressing enter in the input box. Despite ...

What is the best way to connect with the <progress> element?

Vuex.Store({ state: { percentage: 0, }, ... I'm attempting to use the code <progress max="100" v-model="percentage"></progress>, but I keep encountering the error message 'v-model' directives are not supported on <pro ...

My discord.js bot remains silent in response to a user's message, even when no errors are present

My Discord bot is using version 13.1.0 of discord.js and my Node version is 16.7.0. I utilized the commands npm init to generate a package.json file and npm install discord.js to install the Discord package. The code for the bot is written in index.js, an ...

Troubleshooting async/await issues in certain IDEs

I've been experimenting with aysnc and await in my project. While it worked perfectly in FiddleJS, I encountered an error when trying to implement it in my IDE (PHPSTORM 2017): async function test(url){ ^^^^^^^^ SyntaxError: Unexpected token f ...

Unable to retrieve the data-id from the ajax response for extraction and transfer to the modal

I am encountering an issue when trying to retrieve the data-id from an AJAX response within a href tag. The response always returns as undefined. $("#loader_ekpresi").show(); $.ajax({ url:"<?php echo site_url() ?>Home/get_ekspresi", type:& ...

PhoneGap iOS application storing outdated information

My Phonegap 2.1 app running on iOS 6, with jQuery 1.7.2 and JQMobile 1.1.1 libraries, is experiencing an issue where old data from ajax responses gets cached if the app is unused for a few days. The only way to resolve this issue is by reinstalling the a ...

What steps should I take to prompt Postman to interact with a Web API?

I have recently installed the Postman plugin for Chrome and I am curious about how to use it to call my web API. Currently, I am making an AJAX call in JavaScript with the following code: alert("Getting security token"); // Do AJAX call to get security t ...

Problem concerning the window object in a React functional component

Hey there, I am currently facing a situation where I need to access the window object within my React component in order to retrieve some information from the query string. Here is an excerpt of what my component code looks like: export function MyCompone ...

Resetting the Countdown Clock: A Transformation Process

I have implemented a countdown timer script that I found online and made some adjustments to fit my website's needs. While the current setup effectively counts down to a specific date and time, I now require the timer to reset back to a 24-hour countd ...

Troubleshooting error when using " ' " in asp.net for data insertion

Currently, I am encountering an issue while inserting data into a .mdf database via a webpage. The problem arises when I insert words containing the apostrophe symbol " ' ", as it triggers an exception. I attempted to escape the apostrophe using &bsol ...