multiple checkbox answers for one database field....maybe?
- dmch4mleys
- Born


- Joined: Jul 08, 2008
- Posts: 4
- Status: Offline
hi there.
i have a competition whereby users are asked to select a maximum of 5 correct things out of a choice of 12. those things need to be displayed in a database where i can see if the things that were selected are right or wrong. i have a value for the checkbox 'ckb' which i needed for the javascript to work (select 5, more than 5 will bring up an alert) but i need to display all 5 results. how to i do this?
i have gotten the javascript to work so people could only select a maximum of 5. that was based on all the check boxes having the same id. now i need to display the 5 results in the database
this is the script that only allows the user to select up to 5 checkbox values
<script type="text/javascript">
function chkcontrol(j) {
var total=0;
for(var i=0; i < document.form1.ckb.length; i++){
if(document.form1.ckb[i].checked){
total =total +1;}
if(total > 5){
alert("Please Select only five")
document.form1.ckb[j].checked = false ;
return false;
}
}
} </script>
this is the section of code that deals with the checkboxes. they have the same name but the values are different.
now in the database i want to store all 5 results. therefore each row will have the intro info (name, address, email) but it will then have the values of the 5 checkbox values. how can i achieve this?
any helpers on this please?
i have a competition whereby users are asked to select a maximum of 5 correct things out of a choice of 12. those things need to be displayed in a database where i can see if the things that were selected are right or wrong. i have a value for the checkbox 'ckb' which i needed for the javascript to work (select 5, more than 5 will bring up an alert) but i need to display all 5 results. how to i do this?
i have gotten the javascript to work so people could only select a maximum of 5. that was based on all the check boxes having the same id. now i need to display the 5 results in the database
this is the script that only allows the user to select up to 5 checkbox values
Code: [ Select ]
<script type="text/javascript">
function chkcontrol(j) {
var total=0;
for(var i=0; i < document.form1.ckb.length; i++){
if(document.form1.ckb[i].checked){
total =total +1;}
if(total > 5){
alert("Please Select only five")
document.form1.ckb[j].checked = false ;
return false;
}
}
} </script>
- <script type="text/javascript">
- function chkcontrol(j) {
- var total=0;
- for(var i=0; i < document.form1.ckb.length; i++){
- if(document.form1.ckb[i].checked){
- total =total +1;}
- if(total > 5){
- alert("Please Select only five")
- document.form1.ckb[j].checked = false ;
- return false;
- }
- }
- } </script>
this is the section of code that deals with the checkboxes. they have the same name but the values are different.
Code: [ Select ]
<table border='0' width='471' cellspacing='0' cellpadding='1' align=center>
<tr bgcolor="#ffffcc"><td width="59"> </td><td width="290" ><b>Choice</b></td></tr>
<tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Sweet shop" onclick="chkcontrol(0)";></td><td >In the Sweetshop</td></tr>
<tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Playing Chess" onclick="chkcontrol(1)";></td><td >Playing Chess </td></tr>
<tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Sweet Peas Dolls" onclick="chkcontrol(2)";></td><td >With the Sweet Peas Dolls</td></tr>
<tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Hiding between the Hamleys Bears" onclick="chkcontrol(3)" ;></td><td >Hiding between the Hamleys Bears</td></tr>
<tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Racing cars on the Scalextric track" onclick="chkcontrol(4)";></td><td >Racing cars on the Scalextric track</td></tr>
<tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Having lunch in the Regal Tea Cafe" onclick="chkcontrol(5)";></td><td >Having lunch in the Regal Tea Cafe</td></tr>
<tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Trying on a Hamleys Medieval Dress Costume" onclick="chkcontrol(6)";></td><td >Trying on a Hamleys Medieval Dress Costume</td></tr>
<tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Flying a remote controlled plane" onclick="chkcontrol(7)";></td><td >Flying a remote controlled plane </td></tr>
<tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Playing Nerf Tag with Alice" onclick="chkcontrol(8)";></td><td> Playing Nerf Tag with Alice</td></tr>
<tr bgcolor="#ffffff"><td align="center" ><input type=checkbox name=ckb value="Playing with an Infinite Bubble Gun" onclick="chkcontrol(9)";></td><td >Playing with an Infinite Bubble Gun</td></tr>
<tr bgcolor="#ffffff"><td align="center" ><input type=checkbox name=ckb value="Peeking out behind the Lego Clone Trooper" onclick="chkcontrol(10)";></td><td >Peeking out behind the Lego Clone Trooper</td>
</tr>
</table>
<tr bgcolor="#ffffcc"><td width="59"> </td><td width="290" ><b>Choice</b></td></tr>
<tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Sweet shop" onclick="chkcontrol(0)";></td><td >In the Sweetshop</td></tr>
<tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Playing Chess" onclick="chkcontrol(1)";></td><td >Playing Chess </td></tr>
<tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Sweet Peas Dolls" onclick="chkcontrol(2)";></td><td >With the Sweet Peas Dolls</td></tr>
<tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Hiding between the Hamleys Bears" onclick="chkcontrol(3)" ;></td><td >Hiding between the Hamleys Bears</td></tr>
<tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Racing cars on the Scalextric track" onclick="chkcontrol(4)";></td><td >Racing cars on the Scalextric track</td></tr>
<tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Having lunch in the Regal Tea Cafe" onclick="chkcontrol(5)";></td><td >Having lunch in the Regal Tea Cafe</td></tr>
<tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Trying on a Hamleys Medieval Dress Costume" onclick="chkcontrol(6)";></td><td >Trying on a Hamleys Medieval Dress Costume</td></tr>
<tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Flying a remote controlled plane" onclick="chkcontrol(7)";></td><td >Flying a remote controlled plane </td></tr>
<tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Playing Nerf Tag with Alice" onclick="chkcontrol(8)";></td><td> Playing Nerf Tag with Alice</td></tr>
<tr bgcolor="#ffffff"><td align="center" ><input type=checkbox name=ckb value="Playing with an Infinite Bubble Gun" onclick="chkcontrol(9)";></td><td >Playing with an Infinite Bubble Gun</td></tr>
<tr bgcolor="#ffffff"><td align="center" ><input type=checkbox name=ckb value="Peeking out behind the Lego Clone Trooper" onclick="chkcontrol(10)";></td><td >Peeking out behind the Lego Clone Trooper</td>
</tr>
</table>
- <table border='0' width='471' cellspacing='0' cellpadding='1' align=center>
- <tr bgcolor="#ffffcc"><td width="59"> </td><td width="290" ><b>Choice</b></td></tr>
- <tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Sweet shop" onclick="chkcontrol(0)";></td><td >In the Sweetshop</td></tr>
- <tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Playing Chess" onclick="chkcontrol(1)";></td><td >Playing Chess </td></tr>
- <tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Sweet Peas Dolls" onclick="chkcontrol(2)";></td><td >With the Sweet Peas Dolls</td></tr>
- <tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Hiding between the Hamleys Bears" onclick="chkcontrol(3)" ;></td><td >Hiding between the Hamleys Bears</td></tr>
- <tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Racing cars on the Scalextric track" onclick="chkcontrol(4)";></td><td >Racing cars on the Scalextric track</td></tr>
- <tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Having lunch in the Regal Tea Cafe" onclick="chkcontrol(5)";></td><td >Having lunch in the Regal Tea Cafe</td></tr>
- <tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Trying on a Hamleys Medieval Dress Costume" onclick="chkcontrol(6)";></td><td >Trying on a Hamleys Medieval Dress Costume</td></tr>
- <tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Flying a remote controlled plane" onclick="chkcontrol(7)";></td><td >Flying a remote controlled plane </td></tr>
- <tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Playing Nerf Tag with Alice" onclick="chkcontrol(8)";></td><td> Playing Nerf Tag with Alice</td></tr>
- <tr bgcolor="#ffffff"><td align="center" ><input type=checkbox name=ckb value="Playing with an Infinite Bubble Gun" onclick="chkcontrol(9)";></td><td >Playing with an Infinite Bubble Gun</td></tr>
- <tr bgcolor="#ffffff"><td align="center" ><input type=checkbox name=ckb value="Peeking out behind the Lego Clone Trooper" onclick="chkcontrol(10)";></td><td >Peeking out behind the Lego Clone Trooper</td>
- </tr>
- </table>
now in the database i want to store all 5 results. therefore each row will have the intro info (name, address, email) but it will then have the values of the 5 checkbox values. how can i achieve this?
any helpers on this please?
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
March 5th, 2009, 3:32 am
- dmch4mleys
- Born


- Joined: Jul 08, 2008
- Posts: 4
- Status: Offline
hi there
the checkboxes relates to a competition that has 12 answers. the value of the checkbox is the worded answer rather than a number. hence
the onclick relates to a javascript that counts how many boxes have been clicked. once over 5 an alert box comes up.
now what i am stuck on is how to get the 5 answers into the database. atm the checkbox name is 'ckb'. is this ok or does it need changing? each person will have 5 answers therefore the database needs to have 5 columns (1 for each answer) but each answer is down to the individual.
how do i code this so the database reflects this?
the checkboxes relates to a competition that has 12 answers. the value of the checkbox is the worded answer rather than a number. hence
Code: [ Select ]
<td align="center"><input type=checkbox name=ckb value="Sweet shop" onclick="chkcontrol(0)";></td><td >In the Sweetshop</td>
the onclick relates to a javascript that counts how many boxes have been clicked. once over 5 an alert box comes up.
now what i am stuck on is how to get the 5 answers into the database. atm the checkbox name is 'ckb'. is this ok or does it need changing? each person will have 5 answers therefore the database needs to have 5 columns (1 for each answer) but each answer is down to the individual.
how do i code this so the database reflects this?
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 2 posts
- Users browsing this forum: No registered users and 260 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
