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.
passing multipe checkbox values to textbox
Collapse
X
-
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?
Code:<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>New Page 1</title> </head> <body> <form action="car.php" method="post"> Wraps: <input type="text" id="showValues" name="wrap" /><br /> <input onclick="ATHD()" id="1" type="checkbox" name="pr" value="Password Reset" />*Password Reset<br /> <input onclick="ATHD()" id="2" type="checkbox" name="ps" value="Password Setup" />*Password Setup<br /> <input onclick="ATHD()" id="3" type="checkbox" name="fu" value="Firmware Upgrade (if applicable)" />*Firmware Upgrade (if applicable)<br /> <input onclick="ATHD()" id="4" type="checkbox" name="la" value="Local Access Setup" />*Local Access Setup<br /> <input onclick="ATHD()" id="5" type="checkbox" name="ra" value="Remote Access Setup" />*Remote Access Setup<br /> <input onclick="ATHD()" id="6" type="checkbox" name="ma" value="Mobile Access Setup" />*Mobile Access Setup<br /> <input onclick="ATHD()" id="7" type="checkbox" name="rss" value="Recording Schedule Setup" />*Recording Schedule Setup<br /> <input onclick="ATHD()" id="8" type="checkbox" name="pb" value="How to playback video" />*How to playback video<br /> <input onclick="ATHD()" id="9" type="checkbox" name="cv" value="How to convert video" />*How to convert video<br /> <input onclick="ATHD()" id="10" type="checkbox" name="en" value="Email Notification Setup" />*Email Notification Setup<br /> <input onclick="ATHD()" id="11" type="checkbox" name="ptz" value="PTZ Setup (if applicable)" />*PTZ Setup (if applicable)<br /> <input type="hidden" id="hdnValues" /> <textarea id="showValue" row="10" cols="50"></textarea><br /> fruit: <input type="text" id="showValuess" name="ball" /><br /> <input onclick="ATHDU()" id="12" type="checkbox" name="pr" value="Password Reset" />*Password Reset<br /> <input onclick="ATHU()" id="13" type="checkbox" name="ps" value="Password Setup" />*Password Setup<br /> <input onclick="ATHDU()" id="14" type="checkbox" name="fu" value="Firmware Upgrade (if applicable)" />*Firmware Upgrade (if applicable)<br /> <input onclick="ATHDU()" id="15" type="checkbox" name="la" value="Local Access Setup" />*Local Access Setup<br /> <input onclick="ATHDU()" id="16" type="checkbox" name="ra" value="Remote Access Setup" />*Remote Access Setup<br /> <input onclick="ATHDU()" id="17" type="checkbox" name="ma" value="Mobile Access Setup" />*Mobile Access Setup<br /> <input onclick="ATHDU()" id="18" type="checkbox" name="rss" value="Recording Schedule Setup" />*Recording Schedule Setup<br /> <input onclick="ATHDU()" id="19" type="checkbox" name="pb" value="How to playback video" />*How to playback video<br /> <input onclick="ATHDU()" id="20" type="checkbox" name="cv" value="How to convert video" />*How to convert video<br /> <input onclick="ATHDU()" id="21" type="checkbox" name="en" value="Email Notification Setup" />*Email Notification Setup<br /> <input onclick="ATHDU()" id="22" type="checkbox" name="ptz" value="PTZ Setup (if applicable)" />*PTZ Setup (if applicable)<br /> <input type="hidden" id="hdnValues" /> <textarea id="showValue" row="10" cols="50"></textarea><br /> <input type="submit" name="subscribe"> </form> <script type="text/javascript"> // find number of checkboxes (you haven't specified if you // have a set number or not. If you have a set number, just // set checkboxCount to whatever number you have. var checkboxCount = 0; var inputTags = document.getElementsByTagName('input'); for (var i=0, length = inputTags.length; i<length; i++) { if (inputTags[i].type == 'checkbox') { checkboxCount++; } } function ATHD() { var totalValue = ''; for (var i = 1; i < checkboxCount; i++) { if (document.getElementById(i).checked) totalValue += inputTags[i].value + ';'; } document.getElementById("hdnValues").value = totalValue; document.getElementById("showValues").value = totalValue; } </script> </body> </html>
Last edited by Dormilich; Sep 26 '13, 09:51 AM. Reason: Please use [CODE] [/CODE] tags when posting code.Comment
-
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.
PS. you feed on software?Comment
-
Example
If I check two checkboxes then I see the textbox shows two checkboxes' values separated by a comma like "coffee,bee r".
Code:<form name="form1"> <input type="checkbox" name="checkboxname" value="coffee"> <input type="checkbox" name="checkboxname" value="tea"> <input type="checkbox" name="checkboxname" value="beer"> <input type="checkbox" name="checkboxname" value="soda"> <input type="checkbox" name="checkboxname" value="orangejuice"> </form> <form name="form2"> <input type="text" name="textname"> </form>
Comment
-
Did Sherin forget to write javascript?
Code:<form name="form1"> <input type="checkbox" name="fruits1" value="apple"> apple <input type="checkbox" name="fruits1" value="orange" > orange <input type="checkbox" name="fruits1" value="melon" > melon <input type="checkbox" name="fruits1" value="pinapple" > pinapple <input type="checkbox" name="fruits1" value="grape" > grape <input type="checkbox" name="fruits1" value="banana" > banana <input type="checkbox" name="fruits1" value="strawberry" > strawberry </form> <input type="button" value="Button" onclick="clickBtn1()"/> <form name="form2"> <input type="text" name="text1" value="" maxlength="5"> </form> <script> function clickBtn1(){ const arr1 = []; const fruits1 = document.form1.fruits1; for (let i = 0; i < fruits1.length; i++){ if(fruits1[i].checked){ arr1.push(fruits1[i].value); } } document.form2.text1.value = arr1; } </script>
Comment
Comment