开发者

Serialize inputs and select option

开发者 https://www.devze.com 2023-01-26 17:19 出处:网络
Ineed to serialize inputs and selected option in tablerow(tr) <form action=\'\' METHOD=\'post\' id=\'formConfirmOrder\'>

I need to serialize inputs and selected option in table row(tr)

<form action='' METHOD='post' id='formConfirmOrder'>
<table id='viewTableOrders'>
<tr id='vagon1'>
  <td>
   <select name="order[1][rail_path]" title="1">
     <option value="" selected="selected"></option>
     <开发者_Go百科;option value="1">Patch1</option><option value="2">Patch2</option>
     <option value="3" selected="selected">Patch3</option><option value="5">Patch4</option></select>
  </td>
 <td>
<input name="order[1][vagon_id]" value="210" type="hidden"/>
</td>   

    $('#formConfirmOrder > #viewTableOrders tr#vagon1 
                                            select option:selected,
       #formConfirmOrder > #viewTableOrders tr#vagon1 input').serializeArray();

.. *FireBug*Only inputs

[Object { name="order[1][vagon_id]", more...}]

I can`t get selected value from option!

Inputs were serialized. ,but not options.


You need to serialize the <select> not the options...it'll grab the selected <option> elements automatically (by getting the .val() of the <select>, which is an array here), like this:

$('#formConfirmOrder > #viewTableOrders tr#vagon1 select,
   #formConfirmOrder > #viewTableOrders tr#vagon1 input').serializeArray();

Or, if you want all inputs, just use the :input selector, like this:

$('#vagon1 :input').serializeArray();

Since id attributes should be unique, this should work, given valid markup...if your IDs aren't unique, that's another issue you need to address.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号