Sunday, 8 September 2013

ko binding even if button is not clicked

ko binding even if button is not clicked

I have the below code for some reason even before the button is clicked
the binding takes place. Basically I want to show the table after the
button is clicked but it binds as soon as the page is loaded. What am I
doing wrong here?
JS Code
<script type="text/javascript">
ShowHideDiv=ko.observable(false);
function GetResults() {
alert("test"); //<-- both alerts show as soon as the page loads
self.ShowHideDiv(true);
alert(ShowHideDiv());
}
$(document).ready(function () {
ko.applyBindings(new GetResults());
});
</script>
The HTML
<input type="button" id="btnSearch" value="Search"
style="margin-left:60px;margin-top:20px" tabindex="8" data-bind="click:
GetResults" />
<div id="SearchResult" data-bind="visible: ShowHideDiv">
<table width="100%" id="tblSearchResults">
<thead>
<tr>
<th>Child Name</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<!-- to bind results here -->
</tbody>
</table>
</div>

No comments:

Post a Comment