Monakists
Monakists

Reputation: 1

knockout and form's input values

I have been pretty much in love with knockout lately, and here is my first copy-and-paste source snip :rolleyes:. Without luck, I fail to make it work on the local host server, although I already set up the knockout.js in the same directory of the file.php. I hope someone could help.

<script type="text/javascript" src="knockout210.js"></script>
<script type="text/javascript">
    var ViewModel=function(first, last)
    {
        this.firstName=ko.observable(first);
        this.lastName=ko.observable(last);
        this.fullName=ko.computed(function()
        {
            return this.firstName()+" "+this.lastName();
        },this);
    }
    ko.applyBindings(new ViewModel("Planet","Earth"));
</script>
<p>First Name: <input data-bind="value:firstName"/></p>
<p>Last Name: <input data-bind="value:lastName"/></p>
<h2>Hello, <span data-bind="text:fullName"></span>!</h2>

Upvotes: 0

Views: 601

Answers (1)

lucuma
lucuma

Reputation: 18339

I've setup your demo on jsfiddle. It runs perfectly fine. If what you posted is the actual HTML on your page I'd suggest that you include the html, head, and body tags and make sure that knockout210.js is actually being referenced correctly. Also, if you are having trouble with php or whatever, just make a plain old HTML file and it should run.

Here is your exact code that works: http://jsfiddle.net/lucuma/wD8jE/

Upvotes: 1

Related Questions