JQuery.serialize () not handling dropdown list value?

I think this should be a simple thing, but for some reason, all my form values ​​are built perfectly, except for the selected dropdown value, the form below:

<form id="contactform"> <label for="name">Name</label> <input type="text" id=name name=name placeholder="First and last name" tabindex="1" /> <label for="phonenumber">Phone Number</label> <input type="text" id=phonenumber name=phonenumber placeholder="Please enter your phone number" tabindex="2" /> <label for="email">Email</label> <input type="text" id=email name=email placeholder=" example@domain.com " tabindex="3" /> <label for="dropdown">Please Confirm:</label> <select> <option value="question" selected="selected">I have a question</option> <option value="attending">I am attending</option> <option value="not-attending">I am not attending</option> </select> <label for="comment">Your Message</label> <textarea name="comment" id=comment name=comment placeholder="Enter something here, can't think" tabindex="5"></textarea> <input name="submit" type="submit" id="submit" tabindex="6" value="Send Message"/> </form> 

and this is how I serialize it:

 $('#contactform').submit(function() { var query = $(this).serialize(); $.ajax({ type: "POST", url: "send.php", data: query, success: function(data) { // rest of function 

and finally, the PHP bit that I use to set the value as a variable:

 $dropdown = $_POST['dropdown']; 

An example example heading name=sgrggr&phonenumber=55555555555&email=me%40me.com&comment=quick+test , so I focused on why the outlier is not matched.

Thank you for your help.

+7
source share
2 answers

A drop-down list requires the name attribute to be included in the submit.

 <select name="dropdown"> <option value="question" selected="selected">I have a question</option> <option value="attending">I am attending</option> <option value="not-attending">I am not attending</option> </select> 

hope this helps!

+17
source

I faced a similar situation. The SELECT tag has an attribute named form. Define form = "# ID_OF_THE_FORM_YOU_WANT_YOUR_SELECT_TO_ATTACH_TO". Remember to also define an identifier for your FORM.

0
source