Hi,
I have a JS function which includes the following lines: -
var table = document.getElementById("table1");
-
var cells = table.getElementsByTagName("div");
-
for (i = 0; i < cells.length; i++) {
-
checkedCels = cells[i].id;
-
var checkboxes = cells[i].getElementsByTagName("input");
-
Is it possible to set "var table" from more than 1 table (i.e., "table2")? I tried to include the line "var table += document.getEle mentById("table 2");", but it didn't work.
Thanks for any suggestions!
45 9567
The following should do what you're looking for: -
var table = document.getElementById("table1");
-
var cells = table.getElementsByTagName("div");
-
-
table = document.getElementById("table2");
-
var cells2 = table.getElementsByTagName("div");
-
-
var cells = cells.concat(cells2);
-
-
for (i = 0; i < cells.length; i++) {
-
checkedCels = cells[i].id;
-
var checkboxes = cells[i].getElementsByTagName("input");
-
Thanks for the response; however, that doesn't seem to handle the variables the way I'd like. Below is more along the lines of what I *think* I need.
If possible, could someone please fix the syntax? I can't seem to get the assignment checks to work.
Thanks! -
function createOrder() {
-
var checkedData = "";
-
////var table = document.getElementById("table1");
-
////var cells = table.getElementsByTagName("div");
-
var table1 = document.getElementById("table1");
-
var table10 = document.getElementById("table10");
-
if (table1.value != 'undefined') {
-
var cells = table1.getElementsByTagName("div");
-
} else if (table10.value != 'undefined') {
-
var cells = table10.getElementsByTagName("div");
-
acoder 16,027
Recognized Expert Moderator MVP
So you want table1 OR table10, not table1 AND table10? Note that a table doesn't have a value.
Hi!
I'd prefer to have table1 AND table 10 (sorry about the numbering - it's on a log scale!). Any ideas?
Thanks!
Hi!
I'd prefer to have table1 AND table 10 (sorry about the numbering - it's on a log scale for some reason!). I thought OR would work as it loops each time and appends to an array.
Any ideas? -
function createOrder() {
-
var checkedData = "";
-
////var table = document.getElementById("table1");
-
////var cells = table.getElementsByTagName("div");
-
var table1 = document.getElementById("table1");
-
var table10 = document.getElementById("table10");
-
if (table1.value != 'undefined') {
-
var cells = table1.getElementsByTagName("div");
-
} else if (table10.value != 'undefined') {
-
var cells = table10.getElementsByTagName("div");
-
}
-
for (i = 0; i < cells.length; i++) {
-
checkedCels = cells[i].id;
-
var checkedNams = "";
-
var checkedVals = "";
-
var checkedScreen = "";
-
var checkboxes = cells[i].getElementsByTagName("input");
-
for (j = 0; j < checkboxes.length; j++) {
-
if (checkboxes[j].checked) {
-
checkedNams += checkboxes[j].name;
-
}
-
checkedVals = checkboxes[j].value;
-
checkedScreen = checkboxes[0].value;
-
//MIGHT NEED TO POP OFF FIRST ELEMENT IN checkboxes[].value TO REMOVE screen[]
-
}
-
//if ( checkedVals != "" ){
-
checkedData = checkedData.concat(checkedCels + checkedScreen + checkedNams + checkedVals)
-
// }
-
}
-
document.form1.sendData.value = checkedData;
-
}
-
Thanks!
acoder 16,027
Recognized Expert Moderator MVP
I'd prefer to have table1 AND table 10 (sorry about the numbering - it's on a log scale for some reason!). I thought OR would work as it loops each time and appends to an array.
If you want both, why wouldn't the code posted by wyatt not work? It takes the divs from table10 and concatenates them to the divs from table1.
What are you trying to test in the following lines: - if (table1.value != 'undefined') {
-
var cells = table1.getElementsByTagName("div");
-
} else if (table10.value != 'undefined') {
-
var cells = table10.getElementsByTagName("div");
-
}
-
A table doesn't have a value attribute.
Hi! I just retried wyatts code, and the array "checkedDat a" is blank - even if I include a string. Still, I appreciate wyatt's suggestion.
The code you referenced was an attempt to avoid using "concat". I thought that it would set "cells" using the original code which works, depending on which table I had dragged the draggable to.
Here is the code with wyatts suggestion which does not appear to work. More suggestions please!: -
function createOrder() {
-
var checkedData = "";
-
//THIS WORKS WITH 1 TABLE//var table = document.getElementById("table1");
-
//THIS WORKS WITH 1 TABLE//var cells = table.getElementsByTagName("div");
-
//var table1 = document.getElementById("table1");
-
//var table10 = document.getElementById("table10");
-
//if (table1.value != 'undefined') {
-
//var cells = table1.getElementsByTagName("div");
-
//} else if (table10.value != 'undefined') {
-
//var cells = table10.getElementsByTagName("div");
-
//}
-
-
var table = document.getElementById("table1");
-
var cells = table.getElementsByTagName("div");
-
table = document.getElementById("table10");
-
var cells2 = table.getElementsByTagName("div");
-
var cells = cells.concat(cells2);
-
-
for (i = 0; i < cells.length; i++) {
-
checkedCels = cells[i].id;
-
var checkedNams = "";
-
var checkedVals = "";
-
var checkedScreen = "";
-
var checkboxes = cells[i].getElementsByTagName("input");
-
for (j = 0; j < checkboxes.length; j++) {
-
if (checkboxes[j].checked) {
-
checkedNams += checkboxes[j].name;
-
}
-
checkedVals = checkboxes[j].value;
-
checkedScreen = checkboxes[0].value;
-
//MIGHT NEED TO POP OFF FIRST ELEMENT IN checkboxes[].value TO REMOVE screen[]
-
}
-
//if ( checkedVals != "" ){
-
checkedData = checkedData.concat(checkedCels + checkedScreen + checkedNams + checkedVals")
-
// }
-
}
-
document.form1.sendData.value = checkedData;
-
}
-
acoder 16,027
Recognized Expert Moderator MVP
Hi! I just retried wyatts code, and the array "checkedDat a" is blank - even if I include a string.
And it's not blank when using one table?
The code you referenced was an attempt to avoid using "concat". I thought that it would set "cells" using the original code which works, depending on which table I had dragged the draggable to.
Another alternative is to get the elements from the parent of the tables, thus avoiding concatenation.
The code doesn't work with just 1 table either, even if I do:
Could you please show me example code of how this alternative method works?
Thanks!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Byron |
last post by:
Hi,
Javascript confuses me, so I usually limit myself to Dreamweaver's
built-in scripts for stuff like imageswaps. But this time I'm trying to
write something very simple myself. I do most of my stuff in ASP and PHP
so I'm familiar with server-side programming; for some reason JavaScript
syntax trips me up.
I want to assign a value to a variable according to an onclick event,
and then run an if...then on the variable, and according to...
|
by: adamrfrench |
last post by:
Let it be mentioned that Javascript is not my forte, so the solution to
this could very well be a simple one.
I am working on an AJAX function where I can pass a URL and the target
ID in, and have the function update the target ID with the URL. There
is a bit more to it then that, but that is the basics.
my difficulty comes when I try to assign a variable to:
"document.getElementById('-> var gose here <-').innerHTML"
|
by: weston |
last post by:
I've got a piece of code where, for all the world, it looks like this
fails in IE 6:
hometab = document.getElementById('hometab');
but this succeeds:
hometabemt = document.getElementById('hometab');
Has anyone ever seen anything like this before, or am I dreaming?
|
by: paul |
last post by:
HI! How do we send a variable from an Iframe page back to its parent?
I have a script that calculates the iframe's window size but I need to know
how to send that value back to its parent so I can use it there.
Thanks in advance :)
Paul
|
by: ctman770 |
last post by:
Hi Everyone,
Is it faster to save the precise location of an html dom node into a
variable in js, or to use getElementById everytime you need to access
the node?
I want to make my application as fast as possible. I have about 10-20
id tags that need to be accessed and modified from time to time. Would
the jvm perform slowly if I stored all of the dom node strings
"document.node.child...." into a huge js array?
| |
by: Daz |
last post by:
Hi everyone!
Is it possible to take a line of text like so:
<tr><td>title1</td><td>title2</td><td>title3</td><td>title4</td></tr>
And append it to a DOM node such as this:
var nodeToAppendTo = document.getElementById('tbody');
|
by: X l e c t r i c |
last post by:
webtv versions prior to 2.9 do not recognize document.getElementById, so
we have to use a conditional that includes document.all.
I've been trying to use a variable for document.all and
document.getElementById to simplify my functions. It works for the
latest versions of Explorer, Opera, and webtv. It does not work for the
latest versions of Firefox, Netscape, and SeaMonkey.
Here are two examples of what I'm trying to do. It's the "DOM...
|
by: joecap5 |
last post by:
I have a main window from which I want to open a separate side menu window. I then want to create a list of items on that side menu by clicking on the item names in the main window.
So far I am able to click on "Open Menu" and have the side menu open. I can then click on Items and have them added to the side menu using the innerHTML method or the node method.
The trouble comes in when I try to have the side menu opened automatically...
|
by: irixdude |
last post by:
I am trying to create a script to enter the values of an array into a
dynamically generated table 3 columns wide. I have a counter for the
row # that I am using to name/id the row TR node so I an attach 3
cells (3 columns) before attaching the full row to the table. I'm not
sure where the problem is, but in its current form my script doesn't
even generate the first node before stopping with an error. Please let
me know what I'm doing...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |