473,811 Members | 2,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using the DOM to create a table from array of arrays

3 New Member
I have a problem I would be very grateful for any help with:

I need to create a bus timetable using data from arrays and write a table using the DOM to show only those stops and times selected.

I need to have a select list populated with data from an array, and associated with this are a number of different timesI have the script to populate the select options on screen, but i don't know how to then relate that to the data that is returned. Any help would be appreciated:

[HTML]<html>
<head>
<title>Untitled </title>
<script language="JavaS cript" type="text/javascript">

names = new Array("StopA",
"B",
"C",
"D",
"E",
"F",
"G");

times = new Array(
new Array ("10:00","10:05 ","10:10","10:1 5","10:20","10: 25","10.30"),
new Array ("10:10","10:15 ","10:20","10:3 0","10:40","10: 50","11:00"),
)

function arrayToOptions( arr) {
var opts = new Array() ;
var alen = arr.length ;
for (var i = 0; i < alen ; i++) {
opts[i] = new Option(arr[i])
}
return opts ;
}

var optionObj = new Option

</script>


</head>
<body>

<table width="50%" align="center" cellpapdding="2 ">

<form name="bustimeta ble">
<tr><td>Start :

<select name="startStop " size="1">
</select>

<script type="text/javascript" language="JavaS cript">

var opts = arrayToOptions( names);
for (var i =0; i < opts.length; i++) {
document.bustim etable.startSto p.options[i] = opts[i];
}

</script>
</td>

<td>Destination :
<select name="destinati onStop" size="1">
</select>

<script type="text/javascript" language="JavaS cript">

var opts = arrayToOptions( stnNames);

for (var i =0; i < opts.length; i++) {
document.bustim etable.destinat ionStop.options[i] = opts[i];

}

</script>
</td>

<td>Departure time:
<select name="depTime" size="1">
</select>

<script type="text/javascript" language="JavaS cript">

var opts = arrayToOptions( trnTimes[0]);
for (var i =0; i < opts.length; i++) {
document.bustim etable.depTime. options[i] = opts[i];

}

</script>
</td></tr>


<tr><td>
<input type="button" name="show result" value="show result">
</td></tr>

</form>
</table>
</body>
</html>[/HTML]
Mar 25 '07 #1
3 2788
acoder
16,027 Recognized Expert Moderator MVP
Welcome to TSDN.

Use the onchange event handler for the select box to change the times. Pass the value or selectedIndex to get the array value. Then use that to get the new value.

Perhaps you only need one select box. the other two could be text boxes or even <span>s which contain text. Then when an option is selected, the function that is called changes the text displayed.
Mar 26 '07 #2
jshelp
3 New Member
Thanks for your response... I'm still no entirely sure I know what to do - could you give me an example of how it might be used in this case? I thought I would need to use the DOM to create the table no?
Mar 29 '07 #3
jshelp
3 New Member
I'm not sure how the data in the arrays (the time data) can be linked to the particular stops (in the stop array) - All I want to show is something similar to the below, using the data in the initial arrays:

<html>
<table border="12>
<tr><td>Stop A</td><td>10:00</td></tr>
<tr><td>Stop D</td><td>10:15</td></tr>
</table>
</html>

When these particular options are selected from the form.

Can anyone help please?

Thanks.
Apr 12 '07 #4

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

Similar topics

6
2260
by: Bart Nessux | last post by:
How is this done in php? I've tried several variations of the following: contact_array = ($_POST, $_POST, $_POST, $_POST, $_POST); The ultimate goal is to insert the array into a table in a Mysql db.
4
3692
by: Christian Hackl | last post by:
I honestly wasn't able to find an answer for this design question using Google and Google Groups, so I apologize if it is asked too frequently :) Anyway: Let's say I have a multidimensional array of the following kind: $people = array(); // maps age and e-mail address to names $people = array(21, "paul@foo.bar"); $people = array(22, "linda@bar.foo"); $people = array(19, "max@foobar.foobar");
2
4905
by: Dave Smithz | last post by:
Hi there. Because of the lack of a Union query in MySQL 3 I have decided to take the approach where I populate two arrays with values from similar tables in DB. In this case they are `courses` and `lessons` Lets say Courses has fields CourseID(PK), Date, Name, RunBy, Status The lessons table is related to the Courses table in that a Course can have
1
1926
by: moller | last post by:
I'm reposting this under a more appropriate subject since excel really has nothing to do with my problem. I'm new to perl but not to programming in general. I have been trying to put some data into an excel sheet. And it works fine.... if I hardcode the data.
3
437
by: Steve Mauldin | last post by:
I came across an example in the MSDN documentation using RC2 encryption(the link to the article is at the end of this message). When I tried it I had a problem with getting back the same length string that I sent into it. After working on Debugging the code I found two problems. One was in the statement fromEncrypt = New Byte(encrypted.Length) {} where both FromEncrypt and encrypted are both byte arrays and encrypted's length is 24....
0
1162
by: hazz | last post by:
i have an array (or collection if necessary) of Customers with CustomerID and several properties. For each of these Customers I will have a one to many relationship with Customer products. There are separate tables in the database for Buy, Sell, Insurance, etc. I have already gone out to the database to create a collection of customers from that table if they have a status of 'new.'
2
15996
by: kelly | last post by:
Hi, I don't have a code to show you, what I need are references or algorithms so that I'm in a right track. By the way, thanks for introducing me the array or arrays. Now I can continue my script. Now I want to delete a line from a file. Line being the strings I got/saved to/from array of arrays.
14
3139
by: Peter Hallett | last post by:
I would like to set up a string array as a class member, or field, and then populate this array by reading in from a text file, but I cannot find the appropriate syntax. The getter and setter are very unhappy with the idea and the compiler refuses to play ball with any of the attempts I have made to build such a structure. There is no problem when using a single string but a two dimensional array of strings appears to be a very different...
16
3504
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record in a hidden field) I wish the user to be able to edit the data in the table, so I have extracted the records into hiddenfield, textareas, dropdown list and checkbox so that they can make changes. I named these elements as arrays and wish to run an...
0
9727
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
9605
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,...
0
10386
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 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...
1
7669
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
6889
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
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
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
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
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.