Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

take data from table and populate textbox

Status
Not open for further replies.

canajun

Programmer
Sep 28, 2002
57
CA
I want to have a table of different values, which the user can click on a specific value, and transfer this to a textbox.

There will be a number of different tables, each associated to a textbox.

Then I want to add all the textboxes together to make a total..

any ideas?
 
I'm assuming the table is not a DB table, but just displayed on a page.

You can have your numbers be links like:

<a href="myscript.php?myvalue=5">5<a>

Then have your script pick those values up, store them say in a SESSION variable or something similar, and output them to the proper textbox.


Code:
if(isset($_GET['myvalue'])){ 
session_start();
$_SESSION['myvalues'][0]=$GET['myvalue'];

Then check the SESSION for existing values and output them to the proper textboxes.
Code:
if(isset($_SESSION['myvalues'])){

for($i=0;$i<=count($_SESSION['myvalues']);$i++){
echo "<input type=text name='textbox[]' value='". $_SESSION['myvalues'][$i]."'>";
}
}
Then you can loop through the textboxes and add them once the form is submitted.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
That works, but when you click on the link (5), it resubmits the form, losing any data already entered.

Also -- getting two text boxes for some reason.

Perhaps a java script that populated the textboxes when the table was click on?

New to me, and I appreciate the help!
 
The Session are there to keep the data from the links form being lost, but if their are more elements in the form, then their data will not get sent, and will be subsequently lost.

However, Javascript is a viable solution, but for specifics, you'll have to take it up in the JS forum here. forum216.

Although it would probably be nothing more, than having an Onclick behavior on the links that sets the values of the textboxes.

<a href="#" OnClick="document.formname.textboxname.value="5">5</a>

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top