通过js / jquery传递表单数据

时间:2012-01-04 16:07:08

标签: javascript jquery

我有以下代码,当div点击时将div转换为下拉列表 - 完美地工作,但是,我有“on change”设置提交表单并且它传递除下拉/选择中选择的选项之外的所有数据元素,任何想法?

这是js

<script type="text/javascript">
    $(document).ready(function(){

        var choices = "<select class='choices_dropdown' name='list_name' onchange=\"this.form.submit();\">"+"<option value='My list'>My list</option>"

        <?php
        // this loads the select element    
            $wishes4 = mysql_query("select event_id from user_events where user_id = '$userfromcookie'",$db);

            while ($databack444 = mysql_fetch_array($wishes4)) { // cc
            $wishes5 = mysql_query("select event from events_master where event_id = '$databack444[event_id]'",$db);

            $databack555 = mysql_fetch_array($wishes5);

            echo "+\"<option value='".$databack555[event]."'>".$databack555[event]."</option>\"";

            } // close CC
        ?>

        +"</select>";

        $(".update").click(function() {
            var $this = $(this),
            currentChoice;
            // don't continue if there's already a select in this cell
            if ($this.find("select").length != 0)
                return;
            currentChoice = $this.html();
            var $choices = $(choices);
            $this.empty().append($choices);
            $choices.val(currentChoice);
        });

        $(document).on("change", ".choices_dropdown", function() {
            var $this = $(this);
            $this.parent().html($this.val());
            $('#event_update').submit(); /* this submits the form */
            return false;
        });

    });
</script>

和显示div的html是:

echo '<td class="update">
<form action=/list2.html method=post id=event_update>'
.$databack33[list_name].
'<input type="hidden" name="wishlist_id" value='
.$databack33[list_id].
'>
<input type="hidden" name="action" value="update_list">
</form></td>';

0 个答案:

没有答案