473,289 Members | 1,896 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,289 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 2099

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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.