JS variable in PHP

Reply

Join Date: May 2008
Posts: 43
Reputation: yasmena is an unknown quantity at this point 
Solved Threads: 0
yasmena yasmena is offline Offline
Light Poster

JS variable in PHP

 
0
  #1
Oct 12th, 2008
i have a JS that generates fields on the fly
i set a counter so that i can count the no. of fields the user generated
now i need to loop through these fields
and i dont know how to use that JS variable inside PHP


for($i=0;$i< "JS VAR";$i++)

i need help plz
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: JS variable in PHP

 
0
  #2
Oct 12th, 2008
Originally Posted by yasmena View Post
i have a JS that generates fields on the fly
i set a counter so that i can count the no. of fields the user generated
now i need to loop through these fields
and i dont know how to use that JS variable inside PHP


for($i=0;$i< "JS VAR";$i++)

i need help plz
You have to submit the form to a server side script then you can pull the fields in using the $_POST or $_GET superglobals.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss

-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 54
Reputation: HazardTW is an unknown quantity at this point 
Solved Threads: 2
HazardTW HazardTW is offline Offline
Junior Poster in Training

Re: JS variable in PHP

 
0
  #3
Oct 12th, 2008
If those fields have the same NAME, ie.
<input type="text" name="user_input">
<input type="text" name="user_input">
<input type="text" name="user_input">
<input type="text" name="user_input">

When the form that encloses these input's is submitted then the PHP variable on the server would be:
$_GET['user_input']
or
$_POST['user_input']
depending on your method get or post.
It will be an array containing the values of all form elements with the name 'user_input' that belongs to the form that was submitted.

In the PHP file that the form is submitted to try this:
var_export($_GET['user_input'])
or $_POST, whichever you are using and it will dump the structure of array where you should see the values that you had entered into the forms before submission.
This will give you a clear idea of how to retrieve the individual values from that array.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC