Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here's the http://jsfiddle.net/j74pqqat/24/

We can seem to get the Text Box 3 to work correctly.

The expectation for the Text Box 3 is that it would initialize to show the first seat in the ListBox which would be "Steve" and also "Steve" highlight in the ListBox.

And the drop down 3 should show the sandwich for Steve. Then selecting in the ListBox the Text Box 3 and the drop down 3 would change to show the selected item in the ListBox.

And if we make a change to Text Box 3 the ListBox should highlight the change and the Text Box 1 should show the new name and meal

Example :

Text Box 1 = Steve
Text Box 2 = Bert

ListBox

Steve
Bert

If I click Text Box 1 the third text box should change to Steve

If I change Steve to Mary in the text box 3 then the ListBox should show Marythe Text Box 1 should show Mary

If I change Text Box 1 from Mary to Bob then the ListBox and Text Box 3 would change to Bob
Posted

1 solution

There are a couple of issues, the main on being that when you click on either Steve or Bert you are binding your selectedSeat to the seat's name rather than the seat itself because you have optionsValue: 'name' in the binding.

selectedSeat will also be undefined because nothing in the list box is selected. Though you initialise it yourself, after the data bindings run it will be cleared out. So you need to handle the case where there is no selected item when dealing with the bindings for Tex Box 3

You also need to use brackets when dealing with observables, so instead of $root.selectedSeat.name you need to use $root.selectedSeat().name
I've made some quick changes so you can see what I'm talking about.

http://jsfiddle.net/j74pqqat/26/[^]

You may also want to keep an eye on your browsers output console (press F12 in chrome and IE) which will show you any javascript errors. And also check the documentation and examples on knockoutjs.com, the page on options bindings here[^] may help you out in this instance.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900