By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,045 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

passing multipe checkbox values to textbox

P: 5
Hi I have 3 groups of checkbox. One is for fruit platter, cake platter, wraps, .each has 7 checkboxes. I want to add unlimited number of groups and keep checkboxes. So i need a javascript to pass checkbox values to textbox so i can upload to mysql database. For eg:for fruit platter: apple, orange,kiwi fruit, etc. I found couple of javascripts but it works for only one group or one bunch of checkboxes. and i have multiple groups.So i need one javascript which can work with all groups or individual javascripts for each group.
Sep 25 '13 #1
Share this Question
Share on Google+
3 Replies


Dormilich
Expert Mod 5K+
P: 8,639
So i need a javascript to pass checkbox values to textbox so i can upload to mysql database.
give the checkboxes the appropriate name attribute and they submit to the DB themselves.
Sep 25 '13 #2

P: 5
If i use name attribute for eg: name=ball[] . It will create 5 rows for 5 checkboxs. But i want one row for all values of checkbox. I found the javascript which works for only one group of checkboxes. Can u help me to modify the code? Can u give me a javascript for next group fruit?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  5. <title>New Page 1</title>
  6.  
  7.  
  8.  
  9.  
  10. </head>
  11.  
  12. <body>
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. <form action="car.php" method="post">
  21.  
  22.  
  23. Wraps: <input type="text" id="showValues" name="wrap" /><br />
  24.     <input onclick="ATHD()" id="1" type="checkbox" name="pr" value="Password Reset" />*Password Reset<br />
  25.     <input onclick="ATHD()" id="2" type="checkbox" name="ps" value="Password Setup" />*Password Setup<br />
  26.     <input onclick="ATHD()" id="3" type="checkbox" name="fu" value="Firmware Upgrade (if applicable)" />*Firmware Upgrade (if 
  27.  
  28. applicable)<br />
  29.     <input onclick="ATHD()" id="4" type="checkbox" name="la" value="Local Access Setup" />*Local Access Setup<br />
  30.     <input onclick="ATHD()" id="5" type="checkbox" name="ra" value="Remote Access Setup" />*Remote Access Setup<br />
  31.     <input onclick="ATHD()" id="6" type="checkbox" name="ma" value="Mobile Access Setup" />*Mobile Access Setup<br />
  32.     <input onclick="ATHD()" id="7" type="checkbox" name="rss" value="Recording Schedule Setup" />*Recording Schedule Setup<br 
  33.  
  34. />
  35.     <input onclick="ATHD()" id="8" type="checkbox" name="pb" value="How to playback video" />*How to playback video<br />
  36.     <input onclick="ATHD()" id="9" type="checkbox" name="cv" value="How to convert video" />*How to convert video<br />
  37.     <input onclick="ATHD()" id="10" type="checkbox" name="en" value="Email Notification Setup" />*Email Notification Setup<br 
  38.  
  39. />
  40.     <input onclick="ATHD()" id="11" type="checkbox" name="ptz" value="PTZ Setup (if applicable)" />*PTZ Setup (if 
  41.  
  42. applicable)<br />
  43.     <input type="hidden" id="hdnValues" />
  44.     <textarea id="showValue" row="10" cols="50"></textarea><br />
  45.  
  46.  
  47. fruit: <input type="text" id="showValuess" name="ball" /><br />
  48.     <input onclick="ATHDU()" id="12" type="checkbox" name="pr" value="Password Reset" />*Password Reset<br />
  49.     <input onclick="ATHU()" id="13" type="checkbox" name="ps" value="Password Setup" />*Password Setup<br />
  50.     <input onclick="ATHDU()" id="14" type="checkbox" name="fu" value="Firmware Upgrade (if applicable)" />*Firmware Upgrade 
  51.  
  52. (if applicable)<br />
  53.     <input onclick="ATHDU()" id="15" type="checkbox" name="la" value="Local Access Setup" />*Local Access Setup<br />
  54.     <input onclick="ATHDU()" id="16" type="checkbox" name="ra" value="Remote Access Setup" />*Remote Access Setup<br />
  55.     <input onclick="ATHDU()" id="17" type="checkbox" name="ma" value="Mobile Access Setup" />*Mobile Access Setup<br />
  56.     <input onclick="ATHDU()" id="18" type="checkbox" name="rss" value="Recording Schedule Setup" />*Recording Schedule 
  57.  
  58. Setup<br />
  59.     <input onclick="ATHDU()" id="19" type="checkbox" name="pb" value="How to playback video" />*How to playback video<br />
  60.     <input onclick="ATHDU()" id="20" type="checkbox" name="cv" value="How to convert video" />*How to convert video<br />
  61.     <input onclick="ATHDU()" id="21" type="checkbox" name="en" value="Email Notification Setup" />*Email Notification 
  62.  
  63. Setup<br />
  64.     <input onclick="ATHDU()" id="22" type="checkbox" name="ptz" value="PTZ Setup (if applicable)" />*PTZ Setup (if 
  65.  
  66. applicable)<br />
  67.     <input type="hidden" id="hdnValues" />
  68.     <textarea id="showValue" row="10" cols="50"></textarea><br />
  69.  
  70.  
  71. <input type="submit" name="subscribe">
  72. </form>
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79. <script type="text/javascript">
  80.  
  81. // find number of checkboxes (you haven't specified if you 
  82. // have a set number or not. If you have a set number, just 
  83. // set checkboxCount to whatever number you have.
  84. var checkboxCount = 0;
  85. var inputTags = document.getElementsByTagName('input');
  86. for (var i=0, length = inputTags.length; i<length; i++) {
  87.      if (inputTags[i].type == 'checkbox') {
  88.          checkboxCount++;
  89.      }
  90. }
  91.  
  92. function ATHD() {
  93.     var totalValue = '';
  94.     for (var i = 1; i < checkboxCount; i++) {
  95.         if (document.getElementById(i).checked)
  96.             totalValue += inputTags[i].value + ';';
  97.     }
  98.     document.getElementById("hdnValues").value = totalValue;
  99.     document.getElementById("showValues").value = totalValue;
  100. }
  101.  
  102.  
  103. </script>
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110. </body>
  111.  
  112. </html>
Sep 26 '13 #3

Dormilich
Expert Mod 5K+
P: 8,639
If i use name attribute for eg: name=ball[] . It will create 5 rows for 5 checkboxs. But i want one row for all values of checkbox. I found the javascript which works for only one group of checkboxes.
I have no idea what that is supposed to mean.


PS. you feed on software?
Sep 26 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.