jQuery JSON encode set of input values
Posted
by gurun8
on Stack Overflow
See other posts from Stack Overflow
or by gurun8
Published on 2010-05-21T20:57:50Z
Indexed on
2010/05/21
21:00 UTC
Read the original article
Hit count: 434
I need tp serialize a group of input elements but I can't for the life of me figure out this simple task.
I can successfully iterate through the targeted inputs using:
$("#tr_Features :input").each(function() {
...
}
Here's my code, that doesn't work:
var features = new Array();
$("#tr_Features :input").each(function() {
features += {$(this).attr("name"): $(this).val()};
}
Serializing the entire form won't give me what I need. The form has much more than this subset of inputs. This seems like it should be a pretty straightforward task but apparently programming late into a Friday afternoon isn't a good thing.
If it's helpful, here's the form inputs I'm targeting:
<table cellspacing="0" border="0" id="TblGrid_list" class="EditTable" cellpading="0">
<tbody><tr id="tr_Features" class="FormData" rowpos="1">
<td class="CaptionTD ui-widget-content">Cable Family</td>
<td id="td_Features" class="DataTD ui-widget-content" style="white-space: pre;"> <input type="text" value="" id="feature_id:8" name="feature_id:8"></td>
</tr>
<tr id="tr_Features" class="FormData" rowpos="1">
<td class="CaptionTD ui-widget-content">Material</td>
<td id="td_Features" class="DataTD ui-widget-content" style="white-space: pre;"> <input type="text" value="" id="feature_id:9" name="feature_id:9"></td>
</tr>
<tr id="tr_Features" class="FormData" rowpos="1">
<td class="CaptionTD ui-widget-content">Thread Size</td>
<td id="td_Features" class="DataTD ui-widget-content" style="white-space: pre;"> <input type="text" value="" id="feature_id:10" name="feature_id:10"></td>
</tr>
<tr id="tr_Features" class="FormData" rowpos="1">
<td class="CaptionTD ui-widget-content">Attachment Style</td>
<td id="td_Features" class="DataTD ui-widget-content" style="white-space: pre;"> <input type="text" value="" id="feature_id:11" name="feature_id:11"></td>
</tr>
<tr id="tr_Features" class="FormData" rowpos="1">
<td class="CaptionTD ui-widget-content">Feature</td>
<td id="td_Features" class="DataTD ui-widget-content" style="white-space: pre;"> <input type="text" value="" id="feature_id:12" name="feature_id:12"></td>
</tr>
<tr id="tr_Features" class="FormData" rowpos="1">
<td class="CaptionTD ui-widget-content">Comments</td>
<td id="td_Features" class="DataTD ui-widget-content" style="white-space: pre;"> <input type="text" value="" id="feature_id:13" name="feature_id:13"></td>
</tr>
</tbody></table>
© Stack Overflow or respective owner