473,569 Members | 2,782 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

array Issue - Correspoing checkbox and textfield values to behave

Hello All,

I'm trying to figure out this array problem I have. I don't know if
I'm doing this correctly. Anyone want to take a look.

---------------------
Current Situation.
---------------------
I have a form with checkboxes and corresponding textfields for each
checkbox. Here is the HTML

<input type="checkbox" name="shows[]" value="Morning" >Morning</
option># of People<input type="text" name="people[]" value="" />
<input type="checkbox" name="shows[]" value="Lunch">L unch</option># of
People<input type="text" name="people[]" value="" />
<input type="checkbox" name="shows[]" value="Evening" >Evening</
option># of People<input type="text" name="people[]" value="" />

---------------------
Current Problem
---------------------
If I was to fill out the form and check off the "Evening" checkbox
with 15 people in the textbox and looked at the arrays I would have
the following:

shows Array {
[0] =Evening
}

people Array {
[0] =>
[1] =>
[2] =15
}

I guess I was expecting this

shows Array {
[0] =Evening
}

people Array {
[0] =15
}
---------------------
Attempted Solution
---------------------

// Merge Shows Options
function show_Pairing($s , $n) {
return("$s <brest. $n People,<br><br> ");
}

function map_Pairs($s, $n) {
return(array($s =$n));
}

$merged_list = array_map("show _Pairing", $_POST["shows"],
$_POST["people"]);

foreach ($merged_list as $key =$value) {
$shows_list .= ucfirst ($key) ." : ". $value . "<br>";
}
---------------------
Result
---------------------

0. Evening est. people
1. est. people
2. est. 15 people
So what's happening is the checkboxes seem to have their own key
values and the text boxes have their own key values but when I pair
them they don't seem to want to match.
In this example "Evening" should have a key of shows[2] because that's
how it appeared in the list HTML form but that's not happening.
Is there a PHP solution that can deal with this? Do I need to
reconsider how I laid out my HTML?
Looking for a PHP 4.4 solution considering ISP doesn't have PHP 5.

Jul 18 '07 #1
2 2950
| <input type="checkbox" name="shows[]" value="Morning" >Morning</
| option># of People<input type="text" name="people[]" value="" />
| <input type="checkbox" name="shows[]" value="Lunch">L unch</option># of
| People<input type="text" name="people[]" value="" />
| <input type="checkbox" name="shows[]" value="Evening" >Evening</
| option># of People<input type="text" name="people[]" value="" />
|
| ---------------------
| Current Problem
| ---------------------
| If I was to fill out the form and check off the "Evening" checkbox
| with 15 people in the textbox and looked at the arrays I would have
| the following:
|
| shows Array {
| [0] =Evening
| }
|
| people Array {
| [0] =>
| [1] =>
| [2] =15
| }

seems about right. ALL 'text' type inputs will submit. only SELECTED
'checkbox'es submit. just change the html...

<input name='showTime[morning]' type='checkbox' value='morning' >
# of ppl <input name='people[morning]' type='text' value='0'>
<input name='showTime[lunch]' type='checkbox' value='lunch'>
# of ppl <input name='people[lunch]' type='text' value='0'>
<input name='showTime[evening]' type='checkbox' value='evening' >
# of ppl <input name='people[evening]' type='text' value='0'>

now try this:

foreach ($showTime as $timeOfDay =$value)
{
$attendees = $people[$timeOfDay]
if (!$attendees){ continue; }
echo '<pre>' .
($timeOfDay == 'lunch' ? 'At ' : 'In the ') .
$timeOfDay . ', there will be ' . $attendees .
' attendee' . ($attendees == 1 ? '' : 's') .
' coming to see the show.' .
'</pre>';
}

that's pretty straight-forward.
Jul 19 '07 #2
| foreach ($showTime as $timeOfDay =$value)
| {
| $attendees = $people[$timeOfDay]

and don't forget that semi-colon. :)
Jul 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1598
by: LRW | last post by:
Subject line confusing? The whole thing is confusing to me. OK, I think the root of my problem, aside from mental, is array based...but I'm not even sure what I want to do is even possible. So if I can get far enough to know that one way or the other, then I can try to figure out how to do it. But here's the situation: Page 1 I have a...
7
6271
by: damjanu | last post by:
Hi All; I need little help. I have a datasheet form. I allow user to do 'filter by selection'. My form contains a column with values. As user changes selections, I want to calculate totals. I can do this the first time the form loads.
6
10393
by: Chuck Anderson | last post by:
My knowledge of JavaScript is limited. I learn from example and then adapt those examples to suit my needs. I have stumped myself on this one. I have a form with checkboxes that I want to group by using a two dimensional array. <form name=msgs>
1
2252
by: assgar | last post by:
Hi I need help solving a porblem. I have a form that displays a checkbox, service code, description and dropdown with fees on each row. The fee_money and unit array only returns a selected value from the first item (checkbox).
1
1855
by: newbie | last post by:
Hello All, I'm trying to figure out this array problem I have. I don't know if I'm doing this correctly. Anyone want to take a look. --------------------- Current Situation. --------------------- I have a form with checkboxes and corresponding textfields for each checkbox. Here is the HTML
3
4463
by: Pope Pius X2 | last post by:
I have a simple php form that is submitted and the details are emailed to someone. The problem is that there is a checkbox and if the checkbox is clicked then it sends the result as "Yes". However when it's not clicked I'd like the result to appear as "No" but I can't seem to do this. This is my code: <?php $radiobutton = $_REQUEST ; ...
1
1743
pradeepjain
by: pradeepjain | last post by:
Hii, i need help in sorting multidimensianal array... i Read the multi sort function cld not use tht so i need help..This is the code. here the problem is tht i need to take out values from 2 different tables.i am getting the output properly but only thing is tht i need to sort the o/p as per name here fid=6 is designation..uid...
4
6488
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be retrieved using list/menu box. When i check only a single checkbox to insert the checked category ,selecting that category through list box gives out the...
8
6213
by: ALTAFAD | last post by:
How to copy selected (s) textfield, which those selected through checkbox I like to copy in clipboard. Access textfield data when front of the textfield checkbox is checked if not checked it should not copy in clipboard. If text field has data like that altaf/ahmed mr one field checked...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7917
Oralloy
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. ...
0
8118
jinu1996
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...
0
7962
tracyyun
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...
0
6277
agi2029
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...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
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
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.