468,774 Members | 2,655 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,774 developers. It's quick & easy.

Errors in NS 4.7, works in recent browsers, please help

Hello,

I've scoured my books and the web, but am still daunted, hopefully some of
the users in this newsgroup will have advice for my problem.

I am not an experienced javascript programmer, but have gotten my code to
work well, without errors on IE, Opera and netscapes recent builds. While
testing, I found that it doesnt execute on Netscape 4.7

In the head I have a script that creates a custom object/class for products,
with properties and methods.

The properties and methods are then called later in the body to write out
product information. I generate the script and innitialize objects from a
database which writes the class and creates the objects. I wont touch on the
database here, butit writes out static files, so it's not really an issue.
My code follows...

<HTML>
<HEAD>
<script language="JavaScript">
stID = 7
function Prod(tC, tN, tP, tS, tT) {
this.P=tP;//Price
this.S=tS;//Ship
this.T=tT;//Total
this.N=tN;//Name
this.C=tC;//Code
this.U="https://www.mpllc.net/order.aspx?prod=" + this.C + "&st=" +
stID; //URL
this.WP = WP; // WritePrice
function WP() {
document.write(this.P);
}
this.WN = WN; // WriteName
function WN() {
document.write(this.N);
}
this.WS = WS; // WriteShipping Fee
function WS() {
document.write(this.S);
}
this.WT = WT; // WriteTotal
function WT() {
document.write(this.T);
}
this.Link = Link;//Forward browser to purchase
function Link() {
self.location = this.U;
}
this.LN = LN;//Write Link Tag with Product Name as Link Text
function LN() {
str1 = "<a href='" + this.U + "'>" + this.N + "</a>";
document.write(str1);
}
this.LP = LP;//Write Link Tag with Price as Link Text
function LP() {
str1 = "<a href='" + this.U + "'>" + this.P + "</a>";
document.write(str1);
}
this.LS = LS;//Write Link Tag with Shipping as Link Text
function LS() {
str1 = "<a href='" + this.U + "'>" + this.S + "</a>";
document.write(str1);
}
this.LT = LT;//Write Link Tag with Total as Link Text
function LT() {
str1 = "<a href='" + this.U + "'>" + this.T + "</a>";
document.write(str1);
}
this.LB = LB;//Write Link Tag with Buy as Link Text
function LB() {
str1 = "<a href='" + this.U + "'>Buy</a>";
document.write(str1);
}
this.LNP = LNP;//Write Link Tag with Name and Price as Link Text
function LNP() {
str1 = "<a href='" + this.U + "'>" + this.N + " " + this.P + "</a>";
document.write(str1);
}
this.LNT = LNT;//Write Link Tag with Name and Total as Link Text
function LNT() {
str1 = "<a href='" + this.U + "'>" + this.N + " " + this.T + "</a>";
document.write(str1);
}
}
acip_10_30 = new Prod("acip_10_30", "Aciphex 10mg 30", "$179.00",
"$18.00", "$197.00");

</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<a href="javascript:acip_10_30.Link();"><script
language="javascript">acip_10_30.WN();</script></a>
<br />
<a href="javascript:acip_10_30.Link();"><script
language="javascript">document.write(acip_10_30.N) ;</script></a>
<br />
<script language="javascript">acip_10_30.LN();</script>
<br />
<script language="javascript">acip_10_30.LP();</script>
<br />
<script language="javascript">acip_10_30.LS();</script>
<br />
<script language="javascript">acip_10_30.LT();</script>
<br />
<script language="javascript">acip_10_30.LB();</script>
<br /><script language="javascript">acip_10_30.LNP();</script>
<br /><script language="javascript">acip_10_30.LNT();</script>
<br />
</form>
</body>
</HTML>

Regards,

Aaron
Jul 20 '05 #1
2 1342
ASallade wrote:
I am not an experienced javascript programmer, but have gotten my code to
work well, without errors on IE, Opera and netscapes recent builds. While
testing, I found that it doesnt execute on Netscape 4.7
First of all, no version of Netscape 4.7x knows XHTML, so do not
use it if you want to support this UA. And there are other good
reasons for not using XHTML nowadays.[1]

Secondly, there are differences between Netscape 4.7x versions.[2]
In the head I have a script that creates a custom object/class for products,
There are no classes in JavaScript 1.x and its related languages,
you have created a prototype (object) by a constructor (function).[3]
with properties and methods.
Note that every method is a property of type "function" (IE shows
"object" [IMHO falsely] as every function is a Function object.)
The properties and methods are then called later in the body to write out
product information. I generate the script and innitialize objects from a
database which writes the class and creates the objects. I wont touch on the
database here, butit writes out static files, so it's not really an issue.
If you already have a server-side application, use it instead for
the parts that do not work without the server. See below.
My code follows...

<HTML>
<HEAD>
For valid (X)HTML, the DOCTYPE and character set declarations are
required.[4]
<script language="JavaScript">
For valid HTML 4(.01), the "type" attribute is required.[4]
Not that I think NS4 cares much of it, but other UAs will.
stID = 7
You better end all of your statements with a semicolon, do
not rely on auto-completion.
function Prod(tC, tN, tP, tS, tT) {
this.P=tP;//Price
this.S=tS;//Ship
this.T=tT;//Total
this.N=tN;//Name
this.C=tC;//Code
You better allow the properties to have a default value, otherwise
they are assigned "undefined" if an argument is left out:

this.foobar = argument_identifier || default_value;
this.U="https://www.mpllc.net/order.aspx?prod=" + this.C + "&st=" +
stID; //URL
Are you accessing https: from https:? If yes, you have just
run into the Same Origin Policy[5].

If you are writing URIs dynamically, you should escape "&" with
"&amp;" (one time ;-)), for you will create invalid (X)HTML
otherwise.[4]
this.WP = WP; // WritePrice
function WP() {
document.write(this.P);
}
If an inner function is a property anyway, you should assign it
directly:

this.foobar =
function foobar()
{
// ...
};

Note that a "function" statement within a statement (incl. assignment)
requires JavaScript >= 1.2, according to the Core JavaScript 1.5
Reference.[6] (The same Reference states that Netscape 4.x supports
JavaScript 1.2, though it is, alas, not reliable; I found out that
Netscape 4.79 supports anonymous functions [i.e. created using the
"function" operator of JavaScript 1.5/ECMAScript 3] although the
Reference states that Netscape 4.7x supports JavaScript 1.3 only.
So you need to test for it.)

And you better give your methods speaking identifiers from which
you can make a good guess what they actually do.

(Note that document.write(...) overwrites a loaded document, so
do not use it after the document has be loaded, i.e. do not call
methods that call it then. You actually do not do so but remember
this if you are tempted to do so later. There are other DOM
methods you can use instead, even in NN4.)
[...]
}
acip_10_30 = new Prod("acip_10_30", "Aciphex 10mg 30", "$179.00",
"$18.00", "$197.00");
Do not save numeric data as (character) strings. Save it as number
and if a unit (e.g. a currency) is attached to it, save the unit
separately (e.g. through a prototype constructor) or do not save it
at all, depending on your needs.
[...]
<form id="Form1" method="post" runat="server">
This is invalid (X)HTML. The (X)HTML "form"
element does not have a "runat" attribute (in
neither DTD).
<a href="javascript:acip_10_30.Link();"><script
language="javascript">acip_10_30.WN();</script></a>
The javascript: URI scheme is proprietary and used out of
purpose (generating content through Javascript expressions)
here. Use intrinsic event-handler attributes and avoid
"javascript:" if you can, see the FAQ.

Furthermore, including "script" elements in "a" elements
can get you into trouble. You better write the whole
"a" element dynamically, including its content.
<br />
I read this as an XHTML "br" element specified through
SHORTTAG syntax,
<a href="javascript:acip_10_30.Link();"><script
language="javascript">document.write(acip_10_30.N) ;</script></a>
but the "language" attribute is deprecated in both
HTML 4.01 and XHTML 1.0. There is not one in XHTML
1.1.
[...]


So you are generating all of the document's content with client-side
scripting. And what about users, and AFAIS customers, without scripting
support? You are probably looking for a server-side solution, which can
be ECMAScript/J(ava)Script, too, but I recommend PHP or Perl instead.
PointedEars
___________
[1] http://www.hut.fi/u/hsivonen/xhtml-the-point
[2]
http://devedge.netscape.com/library/...e.html#1003515
[3]
http://devedge.netscape.com/library/...2.html#1013803
[4] http://validator.w3.org/
[5] http://www.mozilla.org/projects/secu...me-origin.html
[6]
http://devedge.netscape.com/library/...n.html#1193137
http://devedge.netscape.com/library/...t.html#1004825
http://devedge.netscape.com/library/...s.html#1066344
Jul 20 '05 #2
Thomas 'PointedEars' Lahn wrote:
ASallade wrote:
this.U="https://www.mpllc.net/order.aspx?prod=" + this.C + "&st=" +
stID; //URL


Are you accessing https: from https:?


Err, "https: from http:?", of course.
PointedEars
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Douglas Buchanan | last post: by
12 posts views Thread by Russ | last post: by
1 post views Thread by jamesdylangoldstein | last post: by
10 posts views Thread by Thomas Guettler | last post: by
13 posts views Thread by sheldonlg | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.