jquery .serialize()不处理下拉列表的值? [英] Jquery .serialize() not processing value of dropdown list?

查看:186
本文介绍了jquery .serialize()不处理下拉列表的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这应该是一件简单的事情,但出于某种原因,除了下拉列表的选定值之外,我的所有表单值都被序列化,表单如下:

I think this should be a simple thing but for some reason all my form values are being serialized fine except for the selected value of the dropdown list, the form is 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 am serializing it:

$('#contactform').submit(function() {
    var query = $(this).serialize();

    $.ajax({
        type: "POST",
        url: "send.php",
        data: query,
        success: function(data) { // rest of function

最后我用PHP将这个值设置为一个变量: / p>

and finally the bit of PHP I'm using to set the value as a variable is:

$dropdown     = $_POST['dropdown'];

一个示例标题是 name = sgrggr& phonenumber = 55555555555& email = me%40me.com& comment = quick + test 所以我坚持为什么没有选择下拉值。

AN example header is name=sgrggr&phonenumber=55555555555&email=me%40me.com&comment=quick+test so I'm stuck as to why the dropdown value isn't being picked up.

感谢您的帮助。

推荐答案

您的dropdownlist需要一个名称属性才能包含在提交中。

Your dropdownlist needs a name attribute to be included by 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>

希望这有助于您!

这篇关于jquery .serialize()不处理下拉列表的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆