473,386 Members | 1,803 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,386 software developers and data experts.

passing multipe checkbox values to textbox

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
5 5642
Dormilich
8,658 Expert Mod 8TB
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
bhitra
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
8,658 Expert Mod 8TB
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
Sherin
77 64KB
Example

If I check two checkboxes then I see the textbox shows two checkboxes' values separated by a comma like "coffee,beer".

Expand|Select|Wrap|Line Numbers
  1. <form name="form1">
  2. <input type="checkbox" name="checkboxname" value="coffee">
  3. <input type="checkbox" name="checkboxname" value="tea">
  4. <input type="checkbox" name="checkboxname" value="beer">
  5. <input type="checkbox" name="checkboxname" value="soda">
  6. <input type="checkbox" name="checkboxname" value="orangejuice">
  7. </form>
  8.  
  9. <form name="form2">
  10. <input type="text" name="textname">
  11. </form>
  12.  
  13.  
Nov 6 '20 #5
SioSio
272 256MB
Did Sherin forget to write javascript?
Expand|Select|Wrap|Line Numbers
  1. <form name="form1">
  2.     <input type="checkbox" name="fruits1" value="apple"> apple
  3.     <input type="checkbox" name="fruits1" value="orange" > orange
  4.     <input type="checkbox" name="fruits1" value="melon" > melon
  5.     <input type="checkbox" name="fruits1" value="pinapple" > pinapple
  6.     <input type="checkbox" name="fruits1" value="grape" > grape
  7.     <input type="checkbox" name="fruits1" value="banana" > banana
  8.     <input type="checkbox" name="fruits1" value="strawberry" > strawberry
  9. </form>
  10. <input type="button" value="Button" onclick="clickBtn1()"/>
  11. <form name="form2">
  12.     <input type="text" name="text1" value="" maxlength="5">
  13. </form>
  14. <script>
  15. function clickBtn1(){
  16.     const arr1 = [];
  17.     const fruits1 = document.form1.fruits1;
  18.     for (let i = 0; i < fruits1.length; i++){
  19.         if(fruits1[i].checked){
  20.             arr1.push(fruits1[i].value);
  21.         }
  22.     }
  23.     document.form2.text1.value = arr1;
  24. }
  25. </script>
  26.  
Nov 6 '20 #6

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

Similar topics

6
by: Angelos | last post by:
I have this list of logs stored in a MySQL DB. I display them in a list and next to each log I have a del view LINK I want to add Checkboxes next to each log and keep del and view links as...
0
by: mahsa | last post by:
Hi i want to add checkbox and textbox dynamicly I use this for check box but it has erro CheckBox box = new CheckBox() this.box.CheckedChanged += new System.EventHandler(this.box_CheckedChanged)...
1
by: hazz | last post by:
What do I do to capture the checkbox values as listed below in order to update the database table. There will be an ID field also contained in the row to use in the update query. What would I put...
3
by: shobu | last post by:
passing array checkbox value and update the database <?include 'dbconnect.php'; error_reporting(0);$update_qr="update...
1
by: goutam12345 | last post by:
Hello experts, Please help.... My checkboxes are not passing respective textboxes values to another page My checkboxes are moving in a loop <input type="checkbox" name="chkID" id="chkID" ...
10
by: LionsDome | last post by:
Hello, I have a vb.net page which a bunch of checkboxes. A user can select a checkbox(s) and hit the submit button to store those values in a SQL Server table. This works fine with no problem...
22
by: Mike1961 | last post by:
Checkbox values Hello. I have a problem with this code ASP / Javascript. The problem is JavaScript; try this LINK and select value cespiti 1) With ASP language is populated a secondary...
9
by: raamay | last post by:
I have six checkboxes as shown below: <table> <tr> <td><input name="spec1" type="checkbox" value="0" tabindex="11" /><label id="label">Bridge Construction</label></td> </tr> <tr> <td><input...
1
by: JSharma | last post by:
Hii Everyone I am having a problem while inserting the checkbox values into database after posting. I am actually getting the Checkbox fields from Database .Now I want to insert the Checked field...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.