Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass value in knockout js
    text
    copied!<p>I need to pass value from one javascript to another using function call. I am returning value of month from II js to I js but value is not getting populated in html. Sample code is given below but its not working.Kindly help me to fix this code:</p> <pre><code>HTML FILE ======== &lt;body&gt; &lt;div id="selectdiv"&gt; &lt;input type="radio" id="radio1" name="radioGrp" value='div1' data-bind="checked:subDiv1" /&gt;div1 &lt;input type="radio" id="radio2" name="radioGrp" value='div2' data-bind="checked:subDiv1" /&gt;div2&lt;/div&gt; &lt;div id="myDiv" name="myDiv" class="myDiv" style="font-family: Helvetica; font-size: 12pt; border: 1px solid black;"&gt; &lt;div id="subDiv1" name="subDiv1" data-bind="visible:subDiv1()=='div1'" class="subDiv1" style="color: #FF0000; border: 1px dotted black;"&gt; &lt;h5&gt;Section 1&lt;/h5&gt; &lt;p&gt;MONTHS...&lt;/p&gt; &lt;div id="tabContainer"&gt; &lt;ul data-bind="foreach: subDemoMainObj.months()"&gt; &lt;li&gt; &lt;b data-bind="text: $data"&gt;&lt;/b&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/div&gt; &lt;br /&gt; &lt;div id="subDiv2" name="subDiv2" data-bind="visible:subDiv1()=='div2'" class="subDiv2" style="color: #FF00FF;border: 1px dashed black;"&gt; &lt;h5&gt;Section 2&lt;/h5&gt; &lt;p&gt;This paragraph would be your content paragraph...&lt;/p&gt; &lt;p&gt;Here's another content article right here.&lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; I JS FILE(main js file which is calling II js file for getting value of months) ========= require(["knockout-2.2.1","subDemoMain"], function(ko,demoMain){ $(document).ready(function() { alert("ready"); var vm = function () { var self = this; self.subDiv1 = ko.observable(false); self.subDiv2 = ko.observable(false); self.months = new subDemoMain().getMonths();//ko.observableArray(['Jan', 'Feb', 'Mar', 'etc']); }; /* var getMonths=function(){ return ko.observableArray(['Jan', 'Feb', 'Mar', 'etc']); }*/ // alert("ready2"); ko.applyBindings(new vm()); }); }); II JS FILE ========= define(["knockout-2.2.1"], function(ko){ alert("ready1"); var getMonths=function(){ return ko.observableArray(['Jan', 'Feb', 'Mar', 'etc']); } }, }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload