473,664 Members | 2,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

listing populated TD IDs (+ contents) after drag-drop

127 New Member
Hi all,

I have a table to which an array of cloned checkboxes can be dropped in (using scriptabulous). Could someone please tell me how I can get a list of all populated cells, and which checkboxes within each cell are checked (wuth their dynamically assigned values). For example:

cell 5 => condition 2 selected => box1, box3 checked
cell 9 => condition 1 selected => box4 checked

P.S: Below are relevant(?) snippets of my code.

Thanks!

TABLE (THE TARGET)

[HTML]<table style="text-align: center;" border="2"
cellpadding="2" cellspacing="2" ">
<tbody>
<tr>
<td style="width: 150px; height: 100px;">
<div id="cell1">A1<b r>
Empty</div>
</td>
<td style="width: 150px; height: 100px;">
<div id="cell2">A2<b r>
Empty</div>
</td>
</tr>
<tr>
<td style="width: 150px; height: 100px;">
<div id="cell3">B1<b r>
Empty</div>
</td>
<td style="width: 150px; height: 100px;">
<div id="cell4">B2<b r>
Empty</div>
</td>
</tr>
</tbody>
</table>
[/HTML]
DRAGGABLE CHECKBOXES

[HTML]<div id="l1">
<select name="condition s_list" id="selectField " onChange="updat eValue();">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<br>
<span class="style1">
<span class="style5">
<span style="color: rgb(255, 0, 0);">BOX1</span>
<input id="box1" name="box1[]" value="" type="checkbox" >
<span style="color: rgb(255, 0, 0);">BOX2</span>
<input id="box2" name="box2[]" value="" type="checkbox" ><br>
<span style="color: rgb(255, 0, 0);">BOX3</span>
<input id="box3" name="box3[]" value="" type="checkbox" >
<span style="color: rgb(255, 0, 0);">BOX4</span>
<input id="box4" name="box4[]" value="" type="checkbox" >
</span>
</span>
</div>[/HTML]
Feb 11 '08 #1
13 1369
acoder
16,027 Recognized Expert Moderator MVP
To get the checkboxes in a particular cell:
Expand|Select|Wrap|Line Numbers
  1. // get the cell
  2. var cell = document.getElementById(cellID);
  3. // get the checkboxes (assuming no other input types)
  4. var checkboxes = cell.getElementsByTagName("input");
To get the checked state, the "checked" property will be true or false. You can get the value using the value property.
Feb 11 '08 #2
phub11
127 New Member
Thank you "acoder" for the reply.

Since I'm a JS newbie, I'll ask a few questions so I understand how to follow on from this (I'm still a bit confused with JS syntax):

1) The CellID part of "document.getEl ementById(cellI D)" I assume is a variable refering to the ID of each TD (or DIV in my code). If so, do I need to make a loop for "box1" through "box4" (i.e., box$i).

2) I assume I need something like "if (document.getEl ementById('box$ i').checked)" or, since "var checkboxes = cell.getElement sByTagName("inp ut")" am I way off mark?

3) Would I have this function called with "onSubmit"?

Thanks again!
Feb 11 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
1) The CellID part of "document.getEl ementById(cellI D)" I assume is a variable refering to the ID of each TD (or DIV in my code). If so, do I need to make a loop for "box1" through "box4" (i.e., box$i).
That would be "cell1", "cell2", etc. You could get the table and then call getElementsByTa gName("div") if you're going to loop over all the cells.

2) I assume I need something like "if (document.getEl ementById('box$ i').checked)" or, since "var checkboxes = cell.getElement sByTagName("inp ut")" am I way off mark?
checkboxes would contain an array of checkboxes. You can loop over the array and get the checked property, e.g. checkboxes[i].checked.

3) Would I have this function called with "onSubmit"?
That depends on when you need this information.
Feb 11 '08 #4
phub11
127 New Member
Thanks for the response!

Unfortunately I'm getting more confused. Would it be possible to put some code up which will do roughly want I'm trying to achieve?

If it will help, I've taken the liberty of attaching the code I have at the moment (with CODE tags!!!!!) - NOTE: This doesn't work with IE5 at the moment (dunno why)....

P.S: Thanks for all your help, I really appreciate it!

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.   <title>Untitled Page</title>
  4.   <script src="/script.aculo.us/lib/prototype.js"
  5.  type="text/javascript"></script>
  6.   <script src="/script.aculo.us/src/scriptaculous.js"
  7.  type="text/javascript"></script>
  8.   <script src="/script.aculo.us/src/effects.js"
  9.  type="text/javascript"></script>
  10.   <script src="/script.aculo.us/src/dragdrop.js"
  11.  type="text/javascript"></script>
  12.  
  13. <script type="text/javascript">
  14.  
  15. box1Array = new Array();
  16.  
  17. function AddToDropTargets(id)
  18. {
  19. Droppables.add(id, {accept:null,onDrop: function(sourceelement,targetelement)
  20. {
  21. targetelement.innerHTML = sourceelement.innerHTML;
  22. box1Alt = new Array();
  23. box1Alt = [id];
  24. box1Array = box1Array.concat(box1Alt);
  25. }
  26. });
  27. }
  28.  
  29. function dragstuff()
  30. {
  31. if (!Draggable)
  32. {
  33. alert("libraries did not load");
  34. return;
  35. }
  36. //define draggable element
  37. new Draggable(l1,{revert:true});
  38. //define possible drop targets
  39. AddToDropTargets('cell1');
  40. AddToDropTargets('cell2');
  41. AddToDropTargets('cell3');
  42. AddToDropTargets('cell4');
  43. }
  44.  
  45. function updateValue() {
  46.     document.getElementById('box1').value = document.getElementById('selectField').value;
  47.     document.getElementById('box2').value = document.getElementById('selectField').value;
  48.     document.getElementById('box3').value = document.getElementById('selectField').value;
  49.     document.getElementById('box4').value = document.getElementById('selectField').value;
  50. }
  51.  
  52. function createOrder111()
  53. {
  54. box1=document.forms[0].box1;
  55. txt="";
  56. for (i=0;i<box1.length;++ i)
  57.   {
  58.   if (box1[i].checked)
  59.     {
  60.     txt=txt + box1[i].value + " ";
  61.     }
  62.   }
  63. alert("Fox Box1, you selected condition " + txt + " in " + myArray);
  64. }
  65.  
  66. function createOrder()
  67. {
  68. var cell = document.getElementById(cellID);
  69. var checkboxes = cell.getElementsByTagName("input");
  70. alert("Fox Box1, you selected condition " + checkboxes);
  71. }
  72. </script>
  73.  
  74. </head>
  75. <body onload="dragstuff(); updateValue(); createOrder();">
  76.  
  77. <div id="l1">
  78.  
  79. <select name="conditions_list" id="selectField" onChange="updateValue();">
  80. <option value=""></option>
  81. <option value="1">1</option>
  82. <option value="2">2</option>
  83. <option value="3">3</option>
  84. <option value="4">4</option>
  85. </select>
  86. <br>
  87. <span class="style1">
  88. <span class="style5">
  89.   <span style="color: rgb(255, 0, 0);">BOX1</span>
  90.   <input id="box1" name="box1[]" value="" type="checkbox">
  91.   <span style="color: rgb(255, 0, 0);">BOX2</span>
  92.   <input id="box2" name="box2[]" value="" type="checkbox"><br>
  93.   <span style="color: rgb(255, 0, 0);">BOX3</span>
  94.   <input id="box3" name="box3[]" value="" type="checkbox">
  95.   <span style="color: rgb(255, 0, 0);">BOX4</span>
  96.   <input id="box4" name="box4[]" value="" type="checkbox">
  97. </span>
  98. </span>
  99. </div>
  100. <br>
  101. <form action="junk2.php" method="post" name="form1"
  102.  class="style1 style1">
  103.   <table style="text-align: center;" border="2"
  104.  cellpadding="2" cellspacing="2"">
  105.     <tbody>
  106.       <tr>
  107.         <td style="width: 150px; height: 100px;">
  108.         <div id="cell1">A1<br>
  109. Empty</div>
  110.         </td>
  111.         <td style="width: 150px; height: 100px;">
  112.         <div id="cell2">A2<br>
  113. Empty</div>
  114.         </td>
  115.       </tr>
  116.       <tr>
  117.         <td style="width: 150px; height: 100px;">
  118.         <div id="cell3">B1<br>
  119. Empty</div>
  120.         </td>
  121.         <td style="width: 150px; height: 100px;">
  122.         <div id="cell4">B2<br>
  123. Empty</div>
  124.         </td>
  125.       </tr>
  126.     </tbody>
  127.   </table>
  128.   <br>
  129.   <input name="Submit" value="Submit" type="submit">
  130. <input type="button" onclick="createOrder()" value="Send order">
  131. <input name="reset" type="reset">
  132. </form>
  133. </body>
  134. </html>
  135.  
Feb 11 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
Maybe something like this will work (assuming table has id "table1"):
Expand|Select|Wrap|Line Numbers
  1. function createOrder()
  2. {
  3.   var table = document.getElementById("table1");
  4.   var cells = table.getElementsByTagName("div");
  5.   for (i = 0; i < cells.length; i++) {
  6.     var checkedVals = "";
  7.     var checkboxes = cells[i].getElementsByTagName("input");
  8.     for (j = 0; j < checkboxes.length; j++) {
  9.       if (checkboxes[j].checked) checkedVals += checkboxes[j].value+",";
  10.     }
  11.     alert("For "+cells[i].id+", you selected values " + checkedVals);
  12.   }
  13. }
Feb 12 '08 #6
phub11
127 New Member
Great, thanks for your help!

It *almost* does what I want it to!
Feb 12 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
That's good. So you can adapt it to what you require. If you get stuck, just ask!
Feb 13 '08 #8
phub11
127 New Member
Hi,

For some reason I am having trouble getting this to work in IE6 (works fine in FF2). The "cells" variable gets assigned, but not the value of the checked boxes:

Expand|Select|Wrap|Line Numbers
  1. function updateValue() {
  2.     document.getElementById('box1').value = document.getElementById('selectField').value;
  3. }
  4.  
and this...
Expand|Select|Wrap|Line Numbers
  1. function createOrder() {
  2. var checkedData = "";
  3. var table = document.getElementById("table1");
  4. var cells = table.getElementsByTagName("div");
  5. for (i = 0; i < cells.length; i++) {
  6. checkedCels = cells[i].id;
  7. var checkedNams = "";
  8. var checkedVals = "";
  9. var checkedScreen = "";
  10. var checkboxes = cells[i].getElementsByTagName("input");
  11. for (j = 0; j < checkboxes.length; j++) {
  12. if (checkboxes[j].checked) {
  13. checkedNams += checkboxes[j].name;
  14. }
  15. checkedVals = checkboxes[j].value;
  16. checkedScreen = checkboxes[0].value;
  17. }
  18. if ( checkedVals != "" ){
  19. checkedData = checkedData.concat("For "+checkedCels+" you selected "+checkedScreen+" "+checkedNams+" with value "+checkedVals+" end,")
  20.         }
  21. }
  22. document.form1.sendData.value = checkedData;
  23. }
  24.  
Feb 18 '08 #9
acoder
16,027 Recognized Expert Moderator MVP
For some reason I am having trouble getting this to work in IE6 (works fine in FF2). The "cells" variable gets assigned, but not the value of the checked boxes:
Does the checked property remain the same? It may be that when appended, the checkbox state is reset.
Feb 18 '08 #10

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

Similar topics

7
5838
by: Kate | last post by:
Hi: I have a form with a picture box and some command buttons to make certain shapes appear in the picture box. The shapes are drawn on blank UserControls added like this: 'at top of form module Dim WithEvents tc As testControl 'button1_click (for example)
3
1895
by: yuval | last post by:
Hi DragDrop event is fired by the control accepting the drop If the drop is performed outside the controls I'm watching with events (like on another control/panel/window or outside my app) is there a way for me to know about it? (In MFC, for example, mouse movements are captured) Or do I just have to follow DragEnter/DragLeave and deduce from that?
0
1310
by: Flack | last post by:
Hello, Is it possible to find out how many methods are listening to a certain event? For example, if a number of methods subscribed to a controls DragDrop event using +=, can I find out how many methods in total are listening to the DragDrop event of the control? If I can't find out the exact number of methods listening to the DragDrop event, can I somehow remove all listeners of that event at once? I tried using m_Control.DragDrop =...
0
3878
by: akh | last post by:
I want to use de Drag and Drop ´s event to move a picture box from a form and within a Picture Box. But I have behaviour if the MyPBox As PictureBox as the Globale varible or not Thanks for your help, Here is the code.
3
3786
by: Gary Dunne | last post by:
I'm writing an app that requires drag and drop operation between a ListView and a TreeView control. (The source is the ListView). During the drag drop operation I want to be able to detect the target node in the treeview and auto expand it if applicable... but after a fair bit of head scratching I can't find any easy way to accomplish this. I think what i really need is the equivalent of the HitTest method from the COM version of the...
7
3995
by: JohnR | last post by:
I am using dragdrop to drag and drop a custom class instance. When I drag/drop from one window to another window in the same application everything works fine. But when trying to move between the same windows running in different instances of the application the "dropped" data comes across as a system.__ComObject and I can't CType it to my class to extract the data. I've been searching for hours and haven't found any solution so I am...
4
1614
by: dnfertitta | last post by:
This is my task and I'd like some direction please: 1. Print company that houses user PDF files 2. User logs in and is brought to his own area 3. Dynamic customer inventory page is displayed based on PDF files in a home directory (It would be nice if the MetaTag in a PDF file could be used here)
4
3246
by: techusky | last post by:
I have a *very* simple script written that displays the directory listing of the current working directory, but I am having some difficulty when I try to change folders. Basically, I have my $dir variable set to this: --- $dir = getcwd() . "\\" . $nav; --- but for some reason the script does not actually display the contents of the directory if you change from the directory the script is located in. Here is my code if someone is willing...
1
2169
by: mocolvin | last post by:
I am looking for a Perl script that will do a cleaner job of listing the contents of a directory than what Apache does on its own. I would like the script to create a list of links to enable files in a given directory to be downloaded. The PHP utility that I had been using for that purpose had a security hole that was exploited by hackers.
0
8438
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8549
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8636
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1761
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.