multiple checkbox answers for one database field....maybe?

  • dmch4mleys
  • Born
  • Born
  • dmch4mleys
  • Posts: 4

Post 3+ Months Ago

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
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>
 
  1.  
  2. <script type="text/javascript">
  3. function chkcontrol(j) {
  4. var total=0;
  5. for(var i=0; i < document.form1.ckb.length; i++){
  6. if(document.form1.ckb[i].checked){
  7. total =total +1;}
  8. if(total > 5){
  9. alert("Please Select only five")
  10. document.form1.ckb[j].checked = false ;
  11. return false;
  12. }
  13. }
  14. } </script>
  15.  


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>
 
  1. <table border='0' width='471' cellspacing='0' cellpadding='1' align=center>
  2. <tr bgcolor="#ffffcc"><td width="59"> </td><td width="290" ><b>Choice</b></td></tr>
  3. <tr bgcolor="#f1f1f1"><td align="center"><input type=checkbox name=ckb value="Sweet shop" onclick="chkcontrol(0)";></td><td >In the Sweetshop</td></tr>
  4. <tr bgcolor="#ffffff"><td align="center"><input type=checkbox name=ckb value="Playing Chess" onclick="chkcontrol(1)";></td><td >Playing Chess </td></tr>
  5. <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>
  6. <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>
  7. <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>
  8. <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>
  9. <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>
  10. <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>
  11. <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>
  12. <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>
  13. <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>
  14. </tr>
  15. </table>
  16.  


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
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • dmch4mleys
  • Born
  • Born
  • dmch4mleys
  • Posts: 4

Post 3+ Months Ago

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
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?

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 76 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.