Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have to two textboxes. One is employeename and other is worked hours. employeename is already prefilled. I have to save work hours for each employee, I have to get the work hours in javascript and save them. I am using knockout. There will be a save button for each row.

How to get the changed worked hours from the texbox after they hit save?

UI(UserInterface)
HTML
<tbody data-bind="foreach: arraytoadd">
<tr>
    <td data-bind="text: employeename"></td>
    <td>&lt;input id="indynamicntendtime" data-bind="text: workedhours"/&gt;</td>  
    <td> &lt;input type="button" id="btnsave" value="save"/&gt; </td>                      
</tr>
</tbody>

Javascript
JavaScript
Templatefunction = function()
{
   var self = this;
   self.employeename = ko.observavle("");
   self.workedhours = ko.observale("");
}

RealFunciton = function()
{
   ver self = this;
   self.arrarytoadd = ko.obeservablearray();
   self.addevent = function ()
   {
     self.arraytoadd.push( new Templatefunction);
   }
}

Getting the values from Ajax and assigning
JavaScript
 for(var i=0;i&lt;response.d.length;i++)&gt;
 {
     var x = new TemplateFunction();
     x.employeename(response.d[i].EmployeeName);
     x.workedhours(response.d[i].ActualContractorEndTime);
     jobactivityVM.arraytoadd.push(x);
 }


//TO DO  SAVE FUNCIONALITY. On every row save button click i have to get the corresponding workhours

  $(document).on("click", "[id*=btnsave]", function (e) {
      var x = new TemplateFunction();
      var contractorstarttime = Templatefunction["workedhours"]; //HOW TO GET THE CHANGED WORKED    HOURS .
      //start initialising the parameters needed for the ajax call
      var params = {};        
      params.workedhours=workedhours;

  });
Posted
Updated 18-Dec-14 10:45am
v2

1 solution

You're best off using the click binding on the table row instead of the jQuery click handler. This will return the data for that row.

And next to that you're workedHours variable is a function. You should put parentesis () behind it to get the value.

http://knockoutjs.com/documentation/click-binding.html[^]
 
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