473,411 Members | 2,184 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Yet another newb checkbox question

Hi

I have a newb PHP/Javascript question regarding checkbox processing
I'm not sure which area it falls into so I crossposted to comp.lang.php
and comp.lang.javascript.

I'm trying to construct a checkbox array in a survey form where one
of the choices is "No Preference" which is checked by default.

If the victim chooses other than "No Preference", I'd like to uncheck
the "No Preferences" box and submit the other choices to the rest of the
form as an array.

I have most of it worked out, but I'm stuck on an apparent disconnect
between php and javascript.

When I use this code

____________________example 1 ______________________________________

<head>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Scott Waichler -->

<!-- Shamelessly borrowed from http://www.jsmadeeasy.com/javascript...oxes/index.htm -->

<!-- Begin
function checkChoice(field, i) {
if (i == 0) { // "All" checkbox selected.
if (field[0].checked == true) {
for (i = 1; i < field.length; i++)
field[i].checked = false;
}
}
else { // A checkbox other than "Any" selected.
if (field[i].checked == true) {
field[0].checked = false;
}
}
}
// End -->
</script>

</head>

<body>

<form name=survey_form>

<table>
<tbody>
<tr>
<td>
What is your favorite ethnic food type?&nbsp;&nbsp;<br>
Check all that apply:&nbsp;&nbsp;<br>
</td>
<td>

<input type=checkbox name="food_types" value="No Preference" onclick="checkChoice(document.survey_form.food_typ es, 0)" checked>No Preference:
<br>
<input type=checkbox name="food_types" value="Mexican" onclick="checkChoice(document.survey_form.food_typ es, 1)"> Mexican:
<br>
<input type=checkbox name="food_types" value="Thai" onclick="checkChoice(document.survey_form.food_typ es, 2)"> Thai:
<br>
<input type=checkbox name="food_types" value="Unlisted Food" onclick="checkChoice(document.survey_form.food_typ es, 3)">Unlisted Food Type:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Plea se describe below)
</td>

</td>
</tr>
</tbody>
</table>
</body>
</form>
</center>

____________________ end example 1___________________________________________

the checkboxes act as I would like. The "No Preference" choice is deselected
when another choice is made. Great.

The problem is that php would like to see the selected choices referenced
as "food_types[]" in order to process them as an array. This behavior
is apparently necessary in order to stuff the selections into a database
and for other uses.

This code:

____________________ example 2 ______________________________________

<head>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Scott Waichler -->

<!-- Shamelessly borrowed from http://www.jsmadeeasy.com/javascript...oxes/index.htm -->

<!-- Begin
function checkChoice(field, i) {
if (i == 0) { // "All" checkbox selected.
if (field[0].checked == true) {
for (i = 1; i < field.length; i++)
field[i].checked = false;
}
}
else { // A checkbox other than "Any" selected.
if (field[i].checked == true) {
field[0].checked = false;
}
}
}
// End -->
</script>

</head>

<body>

<form name=survey_form>

<table>
<tbody>
<tr>
<td>
What is your favorite ethnic food type?&nbsp;&nbsp;<br>
Check all that apply:&nbsp;&nbsp;<br>
</td>
<td>

<input type=checkbox name="food_types[]" value="No Preference" onclick="checkChoice(document.survey_form.food_typ es[], 0)" checked>No Preference:
<br>
<input type=checkbox name="food_types[]" value="Mexican" onclick="checkChoice(document.survey_form.food_typ es[], 1)"> Mexican:
<br>
<input type=checkbox name="food_types[]" value="Thai" onclick="checkChoice(document.survey_form.food_typ es[], 2)"> Thai:
<br>
<input type=checkbox name="food_types[]" value="Unlisted Food" onclick="checkChoice(document.survey_form.food_typ es[], 3)">Unlisted Food Type:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(Plea se describe below)
</td>

</td>
</tr>
</tbody>
</table>
</body>
</form>
</center>

______________________ end example 2 ______________________________________

correctly populates the array and everything is fine except for the javascript
part of the code that deselects "No Preference" when another selection is made
no longer works.

I need to know how I can change either the javascript code to work with the []
in the php input statements or some other way to create an array with the choices
that doesn't require the [] to be functional.

I've looked around for a viable solution, but haven't found anything that
seems that it will bridge this disconnect.

Any other suggestions as to how I can do what I'm trying to do are also
extremely appreciated.
Thanks
Claude
Jul 17 '05 #1
0 2107

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

Similar topics

4
by: Jay | last post by:
Hi everybody ! I am currently writing a webpage that displays a list of records ( each record has a checkbox associated with it) to allow users to select any record they want to delete (much...
0
by: David E. | last post by:
So as a programmer, what's the best thing to study? EJB? How much of the J2EE or Enterprise architecture is necessary to no? I guess I need a good overview for a newb like me... thanks.. --...
3
by: Walter | last post by:
But I'm stumped..... I've got a windows 2000 server and I am trying to set up PHPBB on it using a mysql database.. I am very inexperienced on this..... Ive installed mysql V4.0.20d and I can...
3
by: claudel | last post by:
Hi I have a newb PHP/Javascript question regarding checkbox processing I'm not sure which area it falls into so I crossposted to comp.lang.php and comp.lang.javascript. I'm trying to...
10
by: Jennyfer J Barco | last post by:
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox...
4
by: Matrixreloadedth | last post by:
How to change disable color of Checkbox??? I have a checkbox with forecolor in red but when i disable by set Enable properties to false forecolor is changed to gray color but i don't want it. how...
34
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript...
3
by: chiku1523 | last post by:
Hi, Please find the following code. In function setAnswers, I am looping with each question. I have inner loop, which is looping for each answers of the questions. If any of the answer for question...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
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,...
0
isladogs
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...

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.