Get cell and textbox values from a html table when the textboxes have same names

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

    Get cell and textbox values from a html table when the textboxes have same names

    Hi,

    I am trying to get values from table cells and textboxes that have same
    component names in a table after posting to the same page. Javascript is
    able to get the component values while the components have same names. For
    example:

    for (var i=0; i < document.FormTe st.txtTest.leng th; i++)
    {
    alert(document. FormTest.txtTes t[i].value);
    }

    How to do it using PHP? The following is the test code:
    -------------------------------------------------------
    <html>
    <head<title>Tes t</title></head>

    //try to get values after posting
    <?php
    $textboxValue = $_POST['txtTest'];
    echo $textboxValue;
    ?>

    <body bgcolor="#ebeaf f" >
    <form name="FormTest" id="FormTest" action="test.ph p" method="post" >

    <?php
    echo "<table>";
    for ($counter = 0; $counter <= 3; $counter++)
    {
    echo "<tr><td><i nput type='text' name='txtTest'> </td><td>cell
    value</td></tr>";
    }
    echo "</table>";
    ?>

    </form>
    </html>
    -----------------------------------------------

    Thanks.

    GD


  • Rami Elomaa

    #2
    Re: Get cell and textbox values from a html table when the textboxeshave same names

    GD kirjoitti:
    Hi,
    >
    I am trying to get values from table cells and textboxes that have same
    component names in a table after posting to the same page. Javascript is
    able to get the component values while the components have same names. For
    example:
    >
    for (var i=0; i < document.FormTe st.txtTest.leng th; i++)
    {
    alert(document. FormTest.txtTes t[i].value);
    }
    >
    How to do it using PHP? The following is the test code:
    -------------------------------------------------------
    <html>
    <head<title>Tes t</title></head>
    >
    //try to get values after posting
    <?php
    $textboxValue = $_POST['txtTest'];
    echo $textboxValue;
    ?>
    >
    <body bgcolor="#ebeaf f" >
    <form name="FormTest" id="FormTest" action="test.ph p" method="post" >
    >
    <?php
    echo "<table>";
    for ($counter = 0; $counter <= 3; $counter++)
    {
    echo "<tr><td><i nput type='text' name='txtTest'> </td><td>cell
    value</td></tr>";
    }
    echo "</table>";
    ?>
    >
    </form>
    </html>
    -----------------------------------------------
    >
    Add [] to the field names so that php makes an array of them:
    <input type='text' name='txtTest[]'>

    Then you can access them thru $_POST['txtTest'][0] etc...

    --
    Rami.Elomaa@gma il.com
    "Olemme apinoiden planeetalla."

    Comment

    • GD

      #3
      Re: Get cell and textbox values from a html table when the textboxes have same names

      It works great. Thanks!

      GD

      "Rami Elomaa" <rami.elomaa@gm ail.comwrote in message
      news:eunlpr$jke $1@nyytiset.pp. htv.fi...
      GD kirjoitti:
      >Hi,
      >>
      >I am trying to get values from table cells and textboxes that have same
      >component names in a table after posting to the same page. Javascript is
      >able to get the component values while the components have same names.
      >For
      >example:
      >>
      >for (var i=0; i < document.FormTe st.txtTest.leng th; i++)
      > {
      > alert(document. FormTest.txtTes t[i].value);
      > }
      >>
      >How to do it using PHP? The following is the test code:
      >-------------------------------------------------------
      ><html>
      ><head<title>Te st</title></head>
      >>
      >//try to get values after posting
      ><?php
      >$textboxValu e = $_POST['txtTest'];
      >echo $textboxValue;
      >?>
      >>
      ><body bgcolor="#ebeaf f" >
      > <form name="FormTest" id="FormTest" action="test.ph p" method="post" >
      >>
      ><?php
      >echo "<table>";
      >for ($counter = 0; $counter <= 3; $counter++)
      >{
      > echo "<tr><td><i nput type='text' name='txtTest'> </td><td>cell
      >value</td></tr>";
      >}
      >echo "</table>";
      >?>
      >>
      ></form>
      ></html>
      >-----------------------------------------------
      >>
      >
      Add [] to the field names so that php makes an array of them:
      <input type='text' name='txtTest[]'>
      >
      Then you can access them thru $_POST['txtTest'][0] etc...
      >
      --
      Rami.Elomaa@gma il.com
      "Olemme apinoiden planeetalla."

      Comment

      Working...