View Full Version : onClick in NS7 doesn't work
Danne
05-24-2003, 03:27 PM
I can't seem to get onClick, onKeyDown or even that link to work in Netscape 7. Until now I have been spoiled working with IE only.
I tried adapting my code as suggested in this (http://www.codingforums.com/showthread.php?s=&threadid=8530) post.
Here's the code:
<form name="form1">
<input name="txtInput" type="text" onKeyDown="alert();">
<input type="button" value="Button" onClick="alert();">
</form>
<a href="javascript:alert();">
<img src="sp.gif" width=20 height=20></a>
Any suggestions are appreciated!
Philip M
05-24-2003, 03:39 PM
<a href="java script:alert();">
should be
<a href="javascript:alert();">
Danne
05-24-2003, 03:52 PM
Originally posted by Philip M
<a href="java script:alert();">
should be
<a href="javascript:alert();">
That's what I typed. I think it was changed when posted here though...
Philip M
05-25-2003, 07:46 AM
Try removing the semi-colons after alert(); which are redundant.
Is not "alert" a reserved word? Try changing the function name to something else.
brothercake
05-25-2003, 01:54 PM
You want it to do a javascript alert - but in mozilla browsers you can't alert with nothing:
alert('something');
or even
alert('')
would do.
Danne
05-26-2003, 04:34 PM
Thanx brothercake, that's it!
I got a little scared when I didn't even manage to make an alert appearing in netscape...
I even managed to get values from simple input-txt boxes..:rolleyes: I mean in IE it's just:
str=txtInput.value;
...
<input type="text" id="txtInput">
while in netscape:
str = document.form1.txtInput.value;
...
<form name="form1">
<input type="text" name="txtInput">
</form>
It's like learning a whole new language...
brothercake
05-26-2003, 10:54 PM
The one that works in IE is a proprietary shortcut, which some others browsers have adopted, netscape 6 not being among them.
You're better off not using the shortcut syntax, and you don't need to - IE understands the correct one as well:
document.formname.elementname.value
which can also be written as
document.forms["formname"]["elementname"].value
Personally I prefer the latter - more robust, and works in literally every browser that supports javascript.
My best advice is - don't develop in IE and then test afterwards in netscape, because IE supports a whole range of incorrect syntax, and that leads you down garden paths. So do it the other way round - develop in netscape 7 and test it afterwards in IE.
liorean
05-26-2003, 11:02 PM
Not to speak of, the IE approach actually opens up to rather nasty logic problems. You sometimes find you've blocked a feature by chosing a certain name on an element. Using the name 'forms' for an element that sports some type of NodeList, for instance.
Danne
05-27-2003, 03:54 PM
Thanks for the advices!
For the moment I'm not obligated to develop sites that supports netscape, due to the statistical proof of browser use provided by my boss.:p But I'm probably better off using standard solutions anyway, supported by W3C.
brothercake
05-27-2003, 05:00 PM
Sounds like a fair assessment - while IE is the dominant browser by loads - like 95% of all users or something ridiculous like that - that's no reason to adopt an IE-centric programming style, because it ties you into a future where if IE isn't the dominant browser anymore, you'd be screwed.
Can't really second-guess either way, which is why the standards are the only sane point of reference :)
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.