Is it possible to do followng using java script?

D

dbaplusplus

I worked on web development using java script many many years, so I am
now a newbie to javascript. I have a single html page, which is
generated dynamically using some programming language.

Web page will be viewed using Microsoft's IE browser (version 6.x
....). Webapge is self-contained. i.e., it does not refer to any links
outside the webpage, however, it uses
bookmarks inside the same page.

I have a long table to display, table has 50 columns or so. What I want
to do to show
10 columns of the table. 11th column will have a link (more
information). When one clicks
on the link, I will like to dynamically generate another table, which
has 10 more columns and so on.

1. Is there a way to specify in a link to call a java script inside
that page? If yes, how to
do that.
2. When java script is called, can it dynamically generate a table and
display it in a pop-up window. How to do this?


Thanks a lot.
 
V

Vincent van Beveren

Hi dba,
1. Is there a way to specify in a link to call a java script inside
that page? If yes, how to
do that.

2. When java script is called, can it dynamically generate a table and
display it in a pop-up window. How to do this?

function popupAndShow() {
win = window.open('about:blank', '_popup', null);
win.focus();
// if the popup was already opened, this will
// set it to the foreground
win.document.open();
win.document.writeln('<html><head><title>Table</title></head>
win.document.writeln('<body><table>');
win.document.writeln('<tr><td>Hello world</td></tr>');
win.document.writeln('</table></body></html>');
win.document.close();
}

Greetings,
Vincent
 
L

Lasse Reichstein Nielsen

I worked on web development using java script many many years, so I am
now a newbie to javascript.

Well, first things first: Javascript is in one word. In two words, it
sounds like it has something to do with the "Java" language, which
it doesn't. :)
I have a single html page, which is generated dynamically using some
programming language.

Well, the client doesn't care how the page was created, just what
*it* sees.
Web page will be viewed using Microsoft's IE browser (version 6.x
...). Webapge is self-contained. i.e., it does not refer to any
links outside the webpage, however, it uses bookmarks inside the
same page.

I assume "bookmark" is a link to a fragment, i.e.,
I have a long table to display, table has 50 columns or so. What I want
to do to show
10 columns of the table. 11th column will have a link (more
information). When one clicks
on the link, I will like to dynamically generate another table, which
has 10 more columns and so on.

First of all, I'd recommend using a button, not a link. It is not
linking to anything, it's just doing something.

You might want to extend the existing table instead of creating a new
one.
1. Is there a way to specify in a link to call a java script inside
that page? If yes, how to
do that.

Using a link (with a default action if Javascript is disabled):

<a href="#javascriptNotEnabled" onclick="myJavascript()">More info</a>
...

<noscript id="javascriptNotEnabled">
This page requires Active Scripting (Javascript) to be enabled.
It is currently disabled. Please change the setting and reload
the page.
</noscript>

Using a button:
<input type="button" value="More info" onclick="myJavascript()">

The Javascript to call must have been declared, either in an external
file and included:
<script type="text/javascript" src="externalFile.js"></script>
or directly in the page:
<script type="text/javascript">
//...
function myJavascript() {
...
2. When java script is called, can it dynamically generate a table and
display it in a pop-up window. How to do this?

It is possible, but somewhat complicated.

/** data : array of arrays of cell data, with first array being headers */
function popupTable(data,windowFlags) {
var html = ["<title>More information</title><table>"]
for (var i = 0; i < data.length; i++) {
html.push("<tr>");
var row = data;
for (var j = 0; j < row.length; j++) {
html.push((i == 0)?"<th>":"<td>");
html.push(row[j]);
html.push((i == 0)?"<\/th>":"<\/td>");
}
html.push("<\/tr>\n");
}
html.push("</table>");
var htmlString = html.join("").replace(/([\\"])/g,"\\$1");
window.open("javascript:\""+htmlString+"\"","_blank", windowFlags);
}

Example use:

popupTable([["horse","rabbit","aardvark","ostrich"],
["beef","stew","pie","omelet"],
["+","-","*","/"]], "width=240,height=200");

Good luck
/L
 
S

Sevinfooter

What is the source of the tables? Is it pulling datastore information
from the server, or is it static information that you just want to
partially show?
 
R

Randy Webb

Sevinfooter said the following on 7/10/2006 1:28 PM:

Question: How can you spot a Google poster?
Answer: I would tell you but I would have to quote it.

If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

What is the source of the tables?

The "source" of all tables are HTML when displayed in a webpage.
Is it pulling datastore information from the server, or is it
static information that you just want to partially show?

Let me guess, we will see the "AJAX" buzz word if its information from
the server?
 
D

dbaplusplus

Vincent said:
Hi dba,




function popupAndShow() {
win = window.open('about:blank', '_popup', null);
win.focus();
// if the popup was already opened, this will
// set it to the foreground
win.document.open();
win.document.writeln('<html><head><title>Table</title></head>
win.document.writeln('<body><table>');
win.document.writeln('<tr><td>Hello world</td></tr>');
win.document.writeln('</table></body></html>');
win.document.close();
}

Greetings,
Vincent

There is no web-server involved. I have a perl program which generates
this page by getting information from database etc. The script prepare
a self-contained .html file which has all java script and other htnl
code and then look at the page in Microosft IE.


Thanks a lot to all of you for providing quick response. I got the
information which I was looking. This group is very helpful.
 
D

Dr John Stockton

JRS: In article <[email protected]>, dated
Mon, 10 Jul 2006 15:42:36 remote, seen in
Randy Webb said:
The "source" of all tables are HTML when displayed in a webpage.

(A) "is".

(B) No. My <URL:http://www.merlyn.demon.co.uk/estr-bcp.htm#T2> shows a
table which is not in any real way HTML (only in so far as the textarea
which contains it is an HTML construct and the javascript which computes
it lives within HTML tags). A visible table is not necessarily a
<table>.

(C) ISTM that "sevinfooter" wanted the /fons et origo/ of the
information content, without much interest in its representation.
 
N

niels.froehling

I have a long table to display, table has 50 columns or so. What I want
to do to show
10 columns of the table. 11th column will have a link (more
information). When one clicks
on the link, I will like to dynamically generate another table, which
has 10 more columns and so on.

So I suppose you decide to limit it to 10 because it's long.?
Try the easy solution, restrict the tbody's size.

<table style="height: 11em;">
<thead><tr><th>my head, your head</th></tr></thead><!-- 1.2333em -->
<tbody style="height: 10em; overflow: scroll;"><!-- all of your rows,
but only 10em visible --></tbody>
Thanks a lot.

De nada
Niels
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top