0

I'm working on checkout page. I cannot get the selected value from the event.

My Html

<select name="addresslist" id="addresslist" data-bind="event:{ change: regionChange}">
             <option>France</option>
             <option>Germany</option>
</select>

My JS

regionChange:function (data, event) {                     
            console.log(event,"jj")
        }

I'm seeing the event console but can't get the selected value also the selected index is not updating for options when on change even occurs

2 Answers 2

0

Replace your Select Field with This Code

<select name="addresslist" id="addresslist" data-bind="value: regionChange">
             <option>France</option>
             <option>Germany</option>
</select>

Then in js try this code.

this.regionChange = ko.observable();
-1

Please try this

My Html
<select data-bind=""options: availableOptions,
                       value: myfield,
                       optionsCaption: 'Select an element'"">
</select>


My JS
var ViewModel = function() {
    var self = this;
    self.availableOptions = ['France', 'Germany'];
    self.myfield = ko.observable();

    self.myfield.subscribe(function(newValue) {
        // Handle a change here, e.g. update something on the server with Ajax.
        alert('myfield changed to ' + newValue);
    });
}

ko.applyBindings(new ViewModel());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.