Using data-bind on hidden inputs within observable array

45 views
Skip to first unread message

H McA

unread,
Jan 15, 2017, 2:44:23 AM1/15/17
to KnockoutJS
Hi, I've been pulling my hair out for a few hours trying to get this to work - I want to post all variables from an observable array to another php page and decided the way to do it is with hidden inputs and data binding, and using and $index to produce all the names of variables to pass (formagentname0, formagentname1, formagentname2 etc)

This is my code:
<form id="submitagents" name="sendem" method="post" action="details.php">
<table>


   
<!-- Todo: Generate table body -->
   
<tbody data-bind="foreach: seats">
     
<tr>
       
<td data-bind="text: name"></td><input type="hidden" data-bind="attr: { "name": "formagentname" + $index(), value: name}">
       
<td data-bind="text: agency"></td><input type="hidden" data-bind="attr: { "name": "formagencyname" + $index(), value: agency}">
   
</tr>
   
</tbody>
</table>
<button type="submit">Submit</button>
</form>

It does not seem to send any fields to details.php

Any help would be greatly appreciated :)

H McA 

Michael Best

unread,
Jan 15, 2017, 3:33:02 AM1/15/17
to KnockoutJS
In your data-bind, you need to use single quotes or escape the double quotes. Otherwise the data-bind ends after "attr: { "

Also your inputs are between the td elements which might break in some browsers.

-- Michael

H McA

unread,
Jan 15, 2017, 3:53:34 AM1/15/17
to KnockoutJS
Arg can't believe I'm so stupid. 

Thankyou so much.
Reply all
Reply to author
Forward
0 new messages