2

I have multiple forms on one page all are like this: The ID value changes but the options can be similar.

<form class="test"><td>4000</td>
<td align='center'><input type='radio' name='radio' value='car' checked></td>
<td align='center'><input type='radio' name='radio' value='boat' ></td>
<td align='center'><input type='radio' name='radio' value='Plane' ></td>
<input type='hidden' name='id' value='4000'/>
<input type='hidden' name='location' value='local'/>
<div class="form" style="display: none;">
</div></form>

Using JQuery I'm trying to submit this when any of the 3 radio buttons are selected.

<script>
$("input[name='radio']").click(function() {
    var CurrectForm=$(this).parents('.test:first');
    $.post(
        'do.php',
        CurrectForm.serialize(),
        function( response ) {
            CurrectForm.find('#form').html( response );
               show( response );
        }
    );
} );
</script>

I've used similar to the above with checkboxes and dropdown lists, which have worked fine. But this doesn't seem to submit the values to the do.php page. The values that are submitted are show in the div form. Doing a var_dump($_POST); results in an empty array.

Can someone point me in the right direction ? Thanks

Changing the form ti this seems to work ?

<td><form class="test">
<input type='radio' name='radio' value='car' checked>
<input type='radio' name='radio' value='boat' >
<input type='radio' name='radio' value='Plane' >
<input type='hidden' name='id' value='4000'/>
<input type='hidden' name='location' value='local'/>
<div class="form" style="display: none;">
</div></form></td>

Why does changing the cause it to work ?

Jfiddle with working example :) http://jsfiddle.net/QvpH5/

4

1 回答 1

0

我的猜测是,您的页面上有多个带有 class 的表单test。发生的事情是,当您使用 时parents(),您没有意识到它首先找到所有祖先然后搜索 .test:first. 这将返回第一个表单的值,无论单击哪个表单。

查看此 jsFiddle 以查看修复(将 .parents 更改为 .parent):http: //jsfiddle.net/SDzzr/

于 2013-03-19T18:39:21.537 回答