Erlaunis
Erlaunis

Reputation: 1451

Loop through a form which contains another form

I want to loop through a form with Javascript but my problem is that I have another form in the first form.

I'd like to loop through the first form only, not the inner one. I found this method on an other post :

var table = $("#table_cultures tbody");

table.find('tr').each(function (i) {
    var $tds = $(this).find('td'),
        productId = $tds.eq(0).text(),
        product = $tds.eq(1).text(),
        Quantity = $tds.eq(2).text();

    // do something with productId, product, Quantity

    alert('Row ' + (i + 1) + ':\nId: ' + productId
           + '\nProduct: ' + product
           + '\nQuantity: ' + Quantity);
});

This method works but loop through the both forms.

EDIT 1 :

The html looks like :

<form>
    <table>
        <tr>
            <td>Something here</td>
         </tr>
         <tr>
             <td>
                 <form>
                     <table>
                         //tr td ...
                     </table>
                 </form>
             </td>
         </tr>
    </table>
</form>

Upvotes: 0

Views: 50

Answers (1)

or hor
or hor

Reputation: 723

nesting of <form> elements is not allowed

please see: https://www.w3.org/TR/html5/forms.html#the-form-element

"...Flow content, but with no form element descendants..."

Upvotes: 1

Related Questions