...

View Full Version : onclick attribute does not work in NS4



Andrei Todor
08-02-2002, 06:17 PM
I would like to have a text with an onclick attribute that executes something when clicked. The following solution works in Internet Explorer and Netscape6 but does not work in Netscape4:

<div onclick="action()">
Click here
</div>

Does anyone have a solution for achieving this in Netscape4?

Thank you.

joh6nn
08-02-2002, 06:35 PM
You'd have to surround the Div with a link, i'd say. NS4 only supports certain events on certain elements. I rely on a table in the Guide (see my sig) to see which elements support which events in which browsers.

requestcode
08-02-2002, 06:38 PM
Netscape 4 version browsers do not support the onClick in a div tag. You could place some javascript withing the div to check for NS4 and write a link. Something like this:
<DIV>
<SCRIPT LANGUAGE="JavaScript">
if(document.layers)
{
document.write("<A HREF='page.html'>Click Here</A>")
}
</SCRIPT>
</DIV>

The above would only write that out if the browser was NS4. Also make sure that you use single quotes within double quotes.

requestcode
08-02-2002, 07:14 PM
My first example was not very good. Try this one (hopefully it is better).
<html>
<head>
<title>Onclick in a div</title>
<SCRIPT LANGUAGE="JavaScript">
function doalert() {
alert("This worked!")
}
</SCRIPT>
</head>
<body>
<DIV ID="mydiv" onClick="doalert()">
<SCRIPT LANGUAGE="JavaScript">
if(document.layers)
{
document.write("<A HREF='javascript:doalert()'>Click Here</A>")
}
else
{
document.write("Click Here")
}
</SCRIPT>
</DIV>
</body>
</html>

JohnKrutsch
08-03-2002, 12:41 AM
If it is just text you want to click why not just use a normal anchor?

<a href="placetogo.htm" class="myclass">the text here</a>

then in a style sheet you could say how you wanted "myclass" to look.

If you can explain more of what you are trying to do, we can be of more help.

Andrei Todor
08-04-2002, 11:11 AM
Thank you for your suggestions.
In fact, what I want to do is a table whose rows can be selected, in the sense that they are highlighted when clicked and the clicked row number is memorized. I tried to put the whole row in an anchor, but this does not work, it only works with individual table data (td elements). Isn't there a simpler solution?

adios
08-05-2002, 05:42 AM
'Simple' and 'Navigator' probably don't belong in the same sentence - anyway, see what you can make of this:


<html>
<head>
<title>untitled</title>
<style type="text/css">

.rowOFF{
background: #990000;
cursor: hand;
}

.rowON {
background: #cc0000;
cursor: hand;
}

.NScell {
padding-top: 3px;
}

a {
font: 400 16px "times new roman";
color: #ffeeee;
text-decoration: none;
}

</style>
<script type="text/javascript" language="javascript">

var NS_off_bgcolor = '#990000';
var NS_on_bgcolor = '#cc0000';

function hilite_row(row) {
if (!document.layers) row.className = (row.className == 'rowOFF') ? 'rowON' : 'rowOFF';
else {
var l, Ypos = document.anchors[row].y;
for (var i=0; i<document.layers.length; ++i) {
l = document.layers[i];
if (l.pageY == Ypos) {
l.bgColor = (l.lit) ? NS_off_bgcolor : NS_on_bgcolor;
l.lit = !l.lit;
}
}
}
}

</script>
</head>
<body bgcolor="#550000">
<div align="center" style="padding-top:20px;">
<table cellspacing="1" cellpadding="0" border="2">
<tr id="ROW_0" class="rowOFF" onclick="hilite_row(this)">
<td><a href="javascript&#58;void hilite_row('ROW_0')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 0 CELL 1&nbsp;</ilayer></a><a name="ROW_0"></td>
<td><a href="javascript&#58;void hilite_row('ROW_0')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 0 CELL 2&nbsp;</ilayer></a></td>
<td><a href="javascript&#58;void hilite_row('ROW_0')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 0 CELL 3&nbsp;</ilayer></a></td>
<td><a href="javascript&#58;void hilite_row('ROW_0')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 0 CELL 4&nbsp;</ilayer></a></td>
</tr>
<tr id="ROW_1" class="rowOFF" onclick="hilite_row(this)">
<td><a href="javascript&#58;void hilite_row('ROW_1')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 1 CELL 1&nbsp;</ilayer></a><a name="ROW_1"></td>
<td><a href="javascript&#58;void hilite_row('ROW_1')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 1 CELL 2&nbsp;</ilayer></a></td>
<td><a href="javascript&#58;void hilite_row('ROW_1')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 1 CELL 3&nbsp;</ilayer></a></td>
<td><a href="javascript&#58;void hilite_row('ROW_1')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 1 CELL 4&nbsp;</ilayer></a></td>
</tr>
<tr id="ROW_2" class="rowOFF" onclick="hilite_row(this)">
<td><a href="javascript&#58;void hilite_row('ROW_2')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 2 CELL 1&nbsp;</ilayer></a><a name="ROW_2"></td>
<td><a href="javascript&#58;void hilite_row('ROW_2')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 2 CELL 2&nbsp;</ilayer></a></td>
<td><a href="javascript&#58;void hilite_row('ROW_2')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 2 CELL 3&nbsp;</ilayer></a></td>
<td><a href="javascript&#58;void hilite_row('ROW_2')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 2 CELL 4&nbsp;</ilayer></a></td>
</tr>
</table>
</div>
</body>
</html>


Uses an anchor to get the row position. Whatever.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum