473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

GD
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.FormTest.txtTest.length; i++)
{
alert(document.FormTest.txtTest[i].value);
}

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

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

<body bgcolor="#ebeaff" >
<form name="FormTest" id="FormTest" action="test.php" method="post" >

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

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

Thanks.

GD
Apr 1 '07 #1
2 4616
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.FormTest.txtTest.length; i++)
{
alert(document.FormTest.txtTest[i].value);
}

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

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

<body bgcolor="#ebeaff" >
<form name="FormTest" id="FormTest" action="test.php" method="post" >

<?php
echo "<table>";
for ($counter = 0; $counter <= 3; $counter++)
{
echo "<tr><td><input 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...

--
Ra*********@gmail.com
"Olemme apinoiden planeetalla."
Apr 1 '07 #2
GD
It works great. Thanks!

GD

"Rami Elomaa" <ra*********@gmail.comwrote in message
news:eu**********@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.FormTest.txtTest.length; i++)
{
alert(document.FormTest.txtTest[i].value);
}

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

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

<body bgcolor="#ebeaff" >
<form name="FormTest" id="FormTest" action="test.php" method="post" >

<?php
echo "<table>";
for ($counter = 0; $counter <= 3; $counter++)
{
echo "<tr><td><input 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...

--
Ra*********@gmail.com
"Olemme apinoiden planeetalla."

Apr 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Steve B. | last post by:
I have a DataGrid on the left and TextBoxes (TB) on the right. The TB's reflect the contents of the grid cells. Sorting of columns (both thru VS and programmatically) work fine except, when the...
2
by: Alpha | last post by:
Hi, I have a window based program. One of the form has several textboxes and a datagrid. The textboxes are bind to the same dataset table as the datagrid and the text changes to reflect different...
6
by: tshad | last post by:
I have a cell with 2 items in it: a textbox and a link. The link is actually a button (image), but for the example I am using a link, which is doing the same thing. Here is the stripped down...
8
by: tshad | last post by:
I cannot seem to get the asp:textbox to use classes. Style works fine. I am trying to set the textbox to act like a label in some instance so it doesn't have a border, readonly and the background...
2
by: gmalai | last post by:
Hi, I would like to know if it is possible to add a text box in table cell if I **double-click** in that particular table cell(the table was generated at runtime). If so, could you please give...
7
by: Arne Beruldsen | last post by:
in vbnet2005 I have a datagridview. When the user clicks on a row...I would like the contents of certain cells to populate a textbox. To do this...i need to be able to refer to the row and...
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
1
by: colleen1980 | last post by:
Hi: Can any one please tell me that how to i pass the two textbox values in the new page. If i use the form action in the popup window page then the new page is open in the same popup window as i...
1
by: Kageoni2 | last post by:
I'm trying to add new records to my database using 4 textboxes, one for each field in my databases table. I've got ID, Firstname, Surname and Course. But I can't figure out at all how to link...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.