开发者

JQuery multiple id index with form submit

not sure how to do this as ID's are ment to be unique but th开发者_Python百科is is a dynamically series of forms generated from a php array - based on reading the file names in a directory - with the same ID. What I need to do is identify which form so the data can be processed.

Here is the form

echo '<form method="post" action="" id="frmwidget">';
        echo '<tr>';
            echo '<td>';
                echo ucfirst($comments[0]);
            echo '</td><td>';   
                echo $comments[1];
            echo '</td><td align="center">';    
                echo '<input type="checkbox">';
            echo '</td>';
            echo '</td><td align="center">';
                echo '<input type="checkbox">';
            echo '</td>';
            echo '</td><td align="center">';    
                echo '<input type="checkbox">';
            echo '</td>';
            echo '</td><td align="center">';    
                echo '<input type="submit" id="cmdwidgets">';
            echo '</td>';
            echo '</tr>';
    echo '</form>';

And here is my start of the Jquery

$j(document).ready(function() {
$j('#cmdwidgets').live('click',function(){


alert('Your widgets will load');

I will want to Ajax the form in here .. not just an alert

$j('#wall').load("admin/inc/ajax-widgets.php");
return false;
});
});

Yes I know the form could be 1 form not multiples, but for this purpose it needs to be multiple forms. And yes I know the form is incomplete i.e. field names etc.

Any help/suggestions please - thanks in advance


The # selector hooks directly into document.getElementById, so will only get one element back.

To select all your forms, the following selector will suffice:

$("form[id='frmwidget']")

However, I have to ask. Why on earth, do you have dupliate ids? Have you thought about, assigning a class to each and selecting by that? i.e.

$("form.myclass")


Solved it another way but using a UL and indexing the li's

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜