Need to loop thru form elements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeremy Langworthy

    #1

    Need to loop thru form elements

    Hi

    I have a dynamicly generated form (well the elements are at least)
    that looks something like this:

    while( not end of returned records):

    <input name="plan_id[]" type="checkbox" id="" value="<?=
    $row_plans->planid ?>">

    <input name="num_of_po ckets[<?= $row_plans->planid ?>]"
    type="text" id="num_of_pock ets[]" value="<?=
    $row_plans->num_of_pocke ts ?>" size="5" >

    endwhile;

    Basically it loops thru the table and creates a row of fields in the
    form that use the array identifiers '[]' so that I can loop thru them
    with PHP when the page is submitted.

    The key for each array element is the id of the row from the database.
    So checkbox[] (with value "1") and cost[1] are on the same line in the
    form. The next line may not necessarily have cost[2] in it, it may be
    cost[3] or [4], depending the id from the database.

    Is there some way I can loop thru these form elements in javascript?
    Does Javascript store them in an array like PHP does?

    Any help gladly appreciated.
  • steve stevo

    #2
    Re: Need to loop thru form elements

    yep it sure does..

    document.formna me.elements[i]

    and interate through the elements


    "Jeremy Langworthy" <groups@8legs.c o.nz> wrote in message
    news:c7589151.0 308210220.306c0 c03@posting.goo gle.com...[color=blue]
    > Hi
    >
    > I have a dynamicly generated form (well the elements are at least)
    > that looks something like this:
    >
    > while( not end of returned records):
    >
    > <input name="plan_id[]" type="checkbox" id="" value="<?=
    > $row_plans->planid ?>">
    >
    > <input name="num_of_po ckets[<?= $row_plans->planid ?>]"
    > type="text" id="num_of_pock ets[]" value="<?=
    > $row_plans->num_of_pocke ts ?>" size="5" >
    >
    > endwhile;
    >
    > Basically it loops thru the table and creates a row of fields in the
    > form that use the array identifiers '[]' so that I can loop thru them
    > with PHP when the page is submitted.
    >
    > The key for each array element is the id of the row from the database.
    > So checkbox[] (with value "1") and cost[1] are on the same line in the
    > form. The next line may not necessarily have cost[2] in it, it may be
    > cost[3] or [4], depending the id from the database.
    >
    > Is there some way I can loop thru these form elements in javascript?
    > Does Javascript store them in an array like PHP does?
    >
    > Any help gladly appreciated.[/color]


    Comment

    Working...