I would like to add the number in the table cell into the text box
so if I clicked a cell that contained 123 - the text box would show 123
Then if I click the same box again the text box would show 246
If I then clicked a cell containg 987, the text box would show 1233
So each time a table cell is clicked the contents of the cell would be added into my text box.
I think this will need some javascript as the table will be on a HTML form.
Oh and a button click to clear the text box and start again would be REALLY good (but it's beyond me how to even start)
I can understand whats happening - but I am just starting to learn
I learned with the book Teach Yourself Javascript in 24 Hours. There are some online tutorials as well. Webmonkey has one. I've not taken it, but I know it's there.
Once you have the fundamentals down, it should be reasonably simple to accomplish this task.
Someone might spoon feed you the entire answer, but it won't be me. I'll give you a hint though. You will probably want to give id's to all your table detail tags and give them hyperlinks to javascript.
If you didn't want to answer why did you bother putting anything
PS. Your idea of giving ID's to all the TD's is just wrong. It may work fine on a small table but if you have say 10 headers and 20 rows you'll have 200 var-items to sum. What if you have 15 x 30 (you'll have 450 tags, etc)
The way to do it is to define an OnClick function for the table or at least the tr's, which is what I was asking for hhelp on.
Most of the people on ths forum are very helpful, which is why I have answered some questions in the past myself.
Like I said I'll work it out myself (at least your postcount will go up by 2 now, eh)
reflo2
0 Points
7 Posts
Javascript - Sum HTML table cells OnClick into text box
Nov 10, 2012 05:09 PM|LINK
Hi (I'm back again with another question - although for some reason I am now back to being a 0 point person ??, oh well :-
)
I need to Sum the values of a table OnClick.
Say I have a table and text box like this
I would like to add the number in the table cell into the text box
so if I clicked a cell that contained 123 - the text box would show 123
Then if I click the same box again the text box would show 246
If I then clicked a cell containg 987, the text box would show 1233
So each time a table cell is clicked the contents of the cell would be added into my text box.
I think this will need some javascript as the table will be on a HTML form.
Oh and a button click to clear the text box and start again would be REALLY good (but it's beyond me how to even start)
Thanks
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: Javascript - Sum HTML table cells OnClick into text box
Nov 10, 2012 05:13 PM|LINK
It will all be javascript. How well do you know this language?
reflo2
0 Points
7 Posts
Re: Javascript - Sum HTML table cells OnClick into text box
Nov 10, 2012 05:14 PM|LINK
I can understand whats happening - but I am just starting to learn
Dan Bracuk
Contributor
3970 Points
1096 Posts
Re: Javascript - Sum HTML table cells OnClick into text box
Nov 10, 2012 06:33 PM|LINK
I learned with the book Teach Yourself Javascript in 24 Hours. There are some online tutorials as well. Webmonkey has one. I've not taken it, but I know it's there.
Once you have the fundamentals down, it should be reasonably simple to accomplish this task.
Someone might spoon feed you the entire answer, but it won't be me. I'll give you a hint though. You will probably want to give id's to all your table detail tags and give them hyperlinks to javascript.
reflo2
0 Points
7 Posts
Re: Javascript - Sum HTML table cells OnClick into text box
Nov 10, 2012 08:30 PM|LINK
So basically you have killed this question.
It's OK I'll work it out myself.
If you didn't want to answer why did you bother putting anything
PS. Your idea of giving ID's to all the TD's is just wrong. It may work fine on a small table but if you have say 10 headers and 20 rows you'll have 200 var-items to sum. What if you have 15 x 30 (you'll have 450 tags, etc)
The way to do it is to define an OnClick function for the table or at least the tr's, which is what I was asking for hhelp on.
Most of the people on ths forum are very helpful, which is why I have answered some questions in the past myself.
Like I said I'll work it out myself (at least your postcount will go up by 2 now, eh)
Afzaal.Ahmad...
Contributor
2660 Points
1039 Posts
Re: Javascript - Sum HTML table cells OnClick into text box
Nov 11, 2012 06:50 AM|LINK
If you are a beginner. Than I would recommend you to learn JavaScript from the tutorials on this website : https://www.w3schools.com/
~~! FIREWALL !~~
raju dasa
Star
14320 Points
2440 Posts
Re: Javascript - Sum HTML table cells OnClick into text box
Nov 12, 2012 08:48 AM|LINK
Hi,
check this site, for sample and code.
http://jsbin.com/avifab/2/edit
u can modify it for ur purpose.
Note: jquery is used.
rajudasa.blogspot.com || blog@opera