db*********@hotmail.com writes:
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.,
<a href="#someIdInPage">goto foo</a>
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() {
...
</script>
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[i];
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+"\"","_blan k", windowFlags);
}
Example use:
popupTable([["horse","rabbit","aardvark","ostrich"],
["beef","stew","pie","omelet"],
["+","-","*","/"]], "width=240,height=200");
Good luck
/L
--
Lasse Reichstein Nielsen -
lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'