/    Sign up×
Community /Pin to ProfileBookmark

Passing JavaScript variables to PHP

I have an application where JavaScript is used to dynamically build tables, and the number of rows is not static but is based on the user’s actions. Each table row holds data written by JavaScript based on the user selecting a menu option, and also each row has an input form for data to be directly inputted by the user. This is accomplished using DOM (cloneNode and appendChild) as well as having an external JavaScript file modified by PHP.

It works great, and I now have the all the data and want to send it to PHP for server side processing. I don’t think PHP can read the data directly off the page as the table rows don’t have names, however, I can read all the data using DOM. I know how to use JavaScript to create a new script element, transfer variables along with the URL, and retrieve the variables using PHP $_GET. I am concerned that without knowing how many variables are being passed, this might not work.

Any suggestions on how this might best be accomplished would be much appreciated. Thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@balloonbuffoonJan 07.2006 — Send everything in an array, then you can coun't the array to tell how many variables have been sent. So do (for each form element) name="variables['blah']" instead of name="blah" or something like that.

--Steve
Copy linkTweet thisAlerts:
@NotionCommotionauthorJan 08.2006 — Thanks for the help.

Let me make sure I have this right. When you say assign name="variables['blah']", do you mean when creating the form element in html, then have JavaScript do: document.forms.form_name.variables.value=mydata

and then just $_GET ['variables'] in php?

The information I want to transfer is shown below where obj1 = document.getElementById('tbody_id').parentNode.childNodes[0]. How do you envision this being written?

Thanks

obj1.childNodes[0].getElementsByTagName('TD')[0].firstChild.data

obj1.childNodes[1].getElementsByTagName('TD')[0].firstChild.data

obj1.childNodes[2].getElementsByTagName('TD')[0].firstChild.data

obj1.childNodes[3].getElementsByTagName('TD')[0].firstChild.data

etc..

obj1.childNodes[0].getElementsByTagName('TD')[1].firstChild.data

obj1.childNodes[1].getElementsByTagName('TD')[1].firstChild.data

obj1.childNodes[2].getElementsByTagName('TD')[1].firstChild.data

obj1.childNodes[3].getElementsByTagName('TD')[1].firstChild.data

etc..
×

Success!

Help @NotionCommotion spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...