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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculations using multiple array values - advice needed

Status
Not open for further replies.

sjk1000

Programmer
Jan 22, 2009
14
GB
Hi all
I've been stumped over this for days and days now. I have an array in php that I want to perform calculations on via the user clicking radio buttons in a table. The results should be shown instantly on the page. The radio buttons have several values associated with them (in the php array) that will be used in the calculations when the button is clicked.

I've read about hiding the array as a document object so that js can get to it, which I've no experience of doing yet, and I've seen ways of passing the whole array to javascript and then back before the page is submitted, which apparently isn't straightforward. I don't have the experience to say which, if any, of these will work.

In summary (just in case I've baffled everyone :) ), I'm trying to display results of instant calculations on values in a php array following the click of a radio button. What's the best method out there for this?

Any help is very much appreciated. This has driven me more nuts than anything I've done so far. I may go mad soon and I'll take u all with me. :)
Thanks, Steve
 
The syntax of a JS array is fairly simple:

Code:
var someArray = [item1, item2, ... itemN];

As the first step is getting the PHP array onto the page in that format, I'd ask in forum434 how to loop over a PHP array and output it in that format.

Hope this helps,
Dan




Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thanks Dan I'll give them a try too.
Is that what u'd recommend then - sending the array contents to the browser and then back?
Steve
 
If you want to do dynamic calculations on the array, then yes - it'd be a lot quicker, I'd say, than a lot of AJAX calls (or similar).

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top