PHP and javascript
Moderator: General Moderators
PHP and javascript
I have a method coded in javascript, which dynamically adds new textfields when the tab key is pressed.
On the php side, when the user presses the submit button, i need to loop through these textfields...is there any way i can do that? my question is will the php code know that i'm referring to the javascript code??
On the php side, when the user presses the submit button, i need to loop through these textfields...is there any way i can do that? my question is will the php code know that i'm referring to the javascript code??
I assume the text fields have names like "text1" and "text2" etc.
How about you use javascript to change the value of a hidden field to the total of text files, then use PHP to loop through using the variable variable method. Example:
How about you use javascript to change the value of a hidden field to the total of text files, then use PHP to loop through using the variable variable method. Example:
Code: Select all
for ($i = 1; $i <= $total_text_fields; $i++)
{
$v = "text".$i;
$value = $$v; // this is the value in the text box.
}- harrisonad
- Forum Contributor
- Posts: 288
- Joined: Fri Oct 15, 2004 4:58 am
- Location: Philippines
- Contact:
set the name of your textfields to the same name prefixed with "[]" to submit it as array.
something like
That would be retrieve as an array of txtfields
try it.
something like
Code: Select all
...
<input type='text' name='input[]'>
<input type='text' name='input[]'>
<input type='text' name='input[]'>
<input type='text' name='input[]'>
...Code: Select all
$inputs = $_POST['input'];
// $input is now an array with the values of the submitted textfieldsThanks guys.
I've decided to do it in javascript instead, so i'm going to explain in more detail what i need to do, please help if you can.
Below is the method that i have that creates the dynamic textfields on tab press.
now on submit, i need to loop through the x amount of textfields, extract their contents and load them into the sql database.
how would i do that???
I've decided to do it in javascript instead, so i'm going to explain in more detail what i need to do, please help if you can.
Below is the method that i have that creates the dynamic textfields on tab press.
Code: Select all
var numItems = 1; // Number of Items on page
function addNewItem()
{
// Increase the number of items
numItems++;
// Add the rows to the Inner HTML of our TD
document.getElementById("textfields").innerHTML += Description <INPUT TYPE="text" NAME="idescription '+numItems+' " VALUE="" > Part Number <INPUT TYPE="text" NAME="ipartno '+numItems+' " VALUE="" ONKEYDOWN="if (event.keyCode==9) { addNewItem(); }">;
}how would i do that???
Yes thank you so much.
Could you help me with this 2 diminsional array, i'm not sure if this is correct
Could you help me with this 2 diminsional array, i'm not sure if this is correct
Code: Select all
function submitSave()
{
$iarray = array();
for (i=0; i<numItems; i++)
{
// Item Description & Part No
$iDesV = "idescription".$i;
$iDescriptionValue = $$iDesV; // this is the value in the text box.
$iPnoV = "ipartno".$i;
$iPartnoValue = $$iPnoV; // this is the value in the text box.
$iarray[$i] = array($i => $iDescriptionValue, $iPartnoValue);
}
}Actually i'm more concerned with javascript syntax.
Grim, you know how you provided me with this code:
how would i convert that to javascript...i know that javascript doesn't include the $, but can i still do this:
$v = "text".$i;
please advise
Grim, you know how you provided me with this code:
Code: Select all
for ($i = 1; $i <= $total_text_fields; $i++)
{
$v = "text".$i;
$value = $$v; // this is the value in the text box.
}$v = "text".$i;
please advise