I'm building a chart, and it's going through a for loop, which creates new text boxes. I want to be able to save the information put in each text box in some sort of variable array.
Right now it's only letting me save the very last one in a variable I've named $memo. I thought that if I echoed $memo within the loop it would print out each text box's input, but it's only taking the last one and printing that to the screen the amount of textboxes that I have.
This is basically the code in the for loop which is in a form: -
{
-
<input type="text" size="5" name="memo" id="memo" value="" />
-
-
$memo = $_POST['memo'];
-
echo $memo;
-
-
}
-
<input type="submit" name="Save" value="Save" />
Is there a way to set up my text input so that I can do some sort of variable array, like -
<input type="text" size="5" name=$memo[$i] id="memo" value="" />
-
$i++;
Any suggestions? Thanks!
-Coco
5 2669
I am not sure if I completely understand what you are wanting to do, but anyway to answer what I think your question is, yes you can do something like that.
You would want to setup your memo variable something like this.... -
-
$memo[] .= $_POST['memo'];
-
-
And that will create the array variable $memo and add each entry after the last one. So the first key in the array would be 0, or $memo[0].
Then to call the variables in the input section, you would simply use an echo statement something like.... -
-
echo '<input type="text" size="5" name="'.$memo[$i].'" id="memo" value="" />';
-
-
Than each loop through, you will get a different name for that input, as long as you continue to increase $i.
Hope this helps!
pbmods 5,821
Recognized Expert Expert
To nitpick on Lumpy's post: -
$memo[] .= $_POST['memo'];
-
is technically not correct and will generate an E_NOTICE error, because this statement attempts to concatenate a variable that does not exist. -
$memo[] = $_POST['memo'];
-
is the correct method (and produces the expected result).
That's exactly what I want to do, but for some reason it isn't working. I want to echo out the $memo[] array of what was typed in each text box. Any suggestions to what I have done up? Right now it's not echoing out anything.
[PHP]<?
$memo[] = $_POST['memo'];
for($j=0;$j<=6; $j++){
echo '
<form name="saving" method="post" action="">
<td valign="top" height="50" class="Text"><p align="center">
<input type="text" size="5" name="'.$memo[$j].'" id="memo" value="" /></td>';
if(isset( $Save )){
echo $memo[$j];
}
}
echo '</tr>
<input type="submit" name="Save" value="Save" />
</form>';
?>[/PHP]
pbmods 5,821
Recognized Expert Expert
Heya, Coco.
Try this instead: -
?>
-
<form name="saving" method="post" action="">
-
<table>
-
<tr>
-
<?php
-
for( $j = 0; $j < 6; ++$j )
-
{
-
?>
-
<td valign="top" height="50" class="Text">
-
<p align="center">
-
<input type="text" size="5" name="memo[]" value="" />
-
</p>
-
</td>
-
<?php
-
}
-
?>
-
</tr>
-
</table>
-
When the User submits the form, $_POST['memo'] will contain an array.
Thank you! That made my program work perfectly!
JOSH
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Randell D. |
last post by:
HELP!
I am determined to stick with this... I'm getting there... for those who
haven't read my earlier posts, I'm createing what should be a simple
function that I can call to check that required fields in a form have
values. I'm writing the values to the client using document.write only so
that I can confirm that the values are there to be played with - this is not
the final result so please (unless it's leading to the script failure)...
|
by: genetic.error |
last post by:
I'm moving from Vb6 to VB.Net. I have a feeling this has come up
before...
The VS.Net MSDN file seems to state that the following should work:
Form1.Show
Form1.Visible = True
Form1.Hide
Form1.Visible = False
Load (Form1)
|
by: Oleg |
last post by:
Hello there:
I've been trying to create two different sets of required fields in
one form and to use a
radiobutton as sort of a switcher between these sets.
In my HTML form there are two radiobuttons with values 'Via Email' and
'Printed Brochure'.
|
by: umashd |
last post by:
Hi,
I am doing a web based project for my graduation. I studied bit of java
for backend processesing and javascript for the client. Here is the
scenario.
In the FORM, I use INPUT TYPE=text VALUE=" " NAME=cat, and a gif next
to it. User will click on the icon to get a new window. In the new
window, the user selects a value from the pull down menu (created by
servlet from back end) and clicks OK. The value is passed back to the
|
by: Johnny |
last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form
(fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip
code. The user can enter a zip code in the text box and click a button to
determine whether the zip code is unique. If the zip code is not unique,
another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip
code and zipid are both passed to the lookup form/dialog by reference. I...
| |
by: Johnny |
last post by:
I'm a rookie at C# and OO so please don't laugh! I have a form
(fclsTaxCalculator) that contains a text box (tboxZipCode) containing a zip
code. The user can enter a zip code in the text box and click a button to
determine whether the zip code is unique. If the zip code is not unique,
another form/dialog is displayed (fclsLookup) - lookup form/dialog. The zip
code is passed to the lookup form/dialog by reference. I then load a...
|
by: Just Me |
last post by:
I've tried in a few places using a variable name Form and it appears to be
OK.
For example:
Public Shared Sub WritePositionsInRegistry(ByVal Form As Form, ByVal
SubkeyName As String)
Is it OK to use a Type name as a variable name. For example,:
Set(ByVal Color As Color)
|
by: Leszek |
last post by:
Hi.
I wrote a script:
function zmiana(ile){
while(document.getElementById('accomp').childNodes.length>1){
ostatni=document.getElementById('document.dane.accomp').lastChild;
document.getElementById('document.dane.accomp').removeChild(ostatni);
|
by: jedimasta |
last post by:
Good evening all,
I'm a relatively new to javascript, but I've been working with
ColdFusion and PHP for years so I'm not necessarily ignorant, just
stuck and frustrated. Using ColdFusion I'm using an include to pull in
form elements (text fields, checkboxes, etc...) multiple times on a
single page.
The included page does not have a form tag of it's own, but the root
page has uniquely named forms for validation. Imagine it like this:
|
by: Greg Scharlemann |
last post by:
I'm trying to setup a dyamic dropdown list that displays a number of
text fields based on the selected number in the dropdown. The problem
I am running into is capturing the data already entered before the list
is repopulated. For example, suppose the user selects 3 in the drop
down list and 3 text fields are shown. If the user populates the 3 text
fields with data and decides to change the drop down to a list of 4 or
5, how do I capture...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |