Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-02-2002, 05:17 PM   PM User | #1
Andrei Todor
New to the CF scene

 
Join Date: Aug 2002
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Andrei Todor is an unknown quantity at this point
Netscape onclick attribute does not work in NS4

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.
Andrei Todor is offline   Reply With Quote
Old 08-02-2002, 05:35 PM   PM User | #2
joh6nn
wei wu wei


 
joh6nn's Avatar
 
Join Date: Jun 2002
Location: 72° W. 48' 57" , 41° N. 32' 04"
Posts: 1,887
Thanks: 0
Thanked 1 Time in 1 Post
joh6nn is an unknown quantity at this point
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.
__________________
bluemood | devedge | devmo | MS Dev Library | WebMonkey | the Guide

i am a loser geek, crazy with an evil streak,
yes i do believe there is a violent thing inside of me.
joh6nn is offline   Reply With Quote
Old 08-02-2002, 05:38 PM   PM User | #3
requestcode
Regular Coder

 
Join Date: Jun 2002
Posts: 626
Thanks: 0
Thanked 0 Times in 0 Posts
requestcode is an unknown quantity at this point
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 is offline   Reply With Quote
Old 08-02-2002, 06:14 PM   PM User | #4
requestcode
Regular Coder

 
Join Date: Jun 2002
Posts: 626
Thanks: 0
Thanked 0 Times in 0 Posts
requestcode is an unknown quantity at this point
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>
requestcode is offline   Reply With Quote
Old 08-02-2002, 11:41 PM   PM User | #5
JohnKrutsch
Regular Coder

 
Join Date: Jun 2002
Location: The Planet Earth Code Poet: True
Posts: 282
Thanks: 0
Thanked 1 Time in 1 Post
JohnKrutsch is an unknown quantity at this point
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.
JohnKrutsch is offline   Reply With Quote
Old 08-04-2002, 10:11 AM   PM User | #6
Andrei Todor
New to the CF scene

 
Join Date: Aug 2002
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Andrei Todor is an unknown quantity at this point
Netscape

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?
Andrei Todor is offline   Reply With Quote
Old 08-05-2002, 04:42 AM   PM User | #7
adios
Senior Coder

 
Join Date: Jun 2002
Posts: 1,404
Thanks: 2
Thanked 32 Times in 32 Posts
adios is on a distinguished road
'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: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:void hilite_row('ROW_0')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 0 CELL 2&nbsp;</ilayer></a></td>
<td><a href="javascript:void hilite_row('ROW_0')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 0 CELL 3&nbsp;</ilayer></a></td>
<td><a href="javascript: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: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:void hilite_row('ROW_1')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 1 CELL 2&nbsp;</ilayer></a></td>
<td><a href="javascript:void hilite_row('ROW_1')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 1 CELL 3&nbsp;</ilayer></a></td>
<td><a href="javascript: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: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:void hilite_row('ROW_2')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 2 CELL 2&nbsp;</ilayer></a></td>
<td><a href="javascript:void hilite_row('ROW_2')"><ilayer class="NScell" bgcolor="#990000">&nbsp;ROW 2 CELL 3&nbsp;</ilayer></a></td>
<td><a href="javascript: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.
adios is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:26 PM.


Advertisement
Log in to turn off these ads.