Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery serialize does not pick up a select tag in a nested div

Tags:

So I have this form

<form>     <div>         <span class="form_t">I Want To Trade In               <span id="trade_target"></span>          </span>         <span class="form_t">With</span>          <div class="selecting">             <select>                 <option>A Mac</option>                 <option>An Iphone</option>               </select>         </div>     </div>      <table id="tradein_table">         <tr>             <td class="textside">My contact Info</td>         </tr>         <tr>             <td class="textside">Mobile Number</td>             <td class="inputside"><input type="text" name="Mobile" id="t_mobile"/></td>         </tr>         <tr>             <td class="textside">First Name</td>             <td class="inputside"><input type="text" id="t_first" name="Fname"/></td>         </tr>         <tr>                 <td class="textside">Last Name</td>             <td class="inputside"><input type="text" id="t_last" name="Lname"/></td>         </tr>            <tr>                 <td class="textside">Email</td>             <td class="inputside"><input type="text" id="t_email" name="Email"/></td>         </tr>         <tr>                 <td class="textside">Company</td>             <td class="inputside"><input id="t_company" type="text" name="Company"/>         </td>               </tr>     </table>      <div class="submit_div">         <input class="submit_form" type="submit" name="Submit" value="Submit" />     </div>   </form> 

And when I run it through jQuery serialize() it picks up all the tags except the select tag in the div.
Any ideas how to get it as well ?

like image 646
Patsy Issa Avatar asked Jun 27 '12 09:06

Patsy Issa


1 Answers

serialize only "picks up" elements with name attribute.

<select name="foo">     <option>A Mac</option>     <option>An Iphone</option>   </select> 

Your's:

<select>     <option>A Mac</option>     <option>An Iphone</option>   </select> 

Won't work.

For a form element's value to be included in the serialized string, the element must have a name attribute.

docs

like image 88
gdoron is supporting Monica Avatar answered Oct 01 '22 22:10

gdoron is supporting Monica