Is this too far off topic??

A

Al Jones

Could I get you to take a look at www.brendasfire.com/amej/darvan.html
andoffer suggestions before I jump off into something I can't crawl out of.

This will be run on a local machine, the intent is that the information
from the pop-up will be printed to a local printer.

Basically any comments on direction will be appreciated.

Apologies ahead of time for cross posting to both groups but I hope
someone will offer guidance.
 
R

RobG

Al said:
Could I get you to take a look at www.brendasfire.com/amej/darvan.html
andoffer suggestions before I jump off into something I can't crawl out of.

1. *Always* specify units - 800 m, 400 m, etc.

2. The abbreviation for centimetre is cm, not CM. Incidentally, cm is
not an official unit of measure, but metre (m) is - but that is way
to picky for your application.

If you intend the results to be sent to some official sports body,
consider making all measurements metres (at least seek the opinion
of a few reputable organisations for their opinion).

3. If there is a choice of only two values (yes/no, on/off), use a
checkbox:

<label for="hurdles400">400&nbsp;m&nbsp;Hurdles:&nbsp<input
type="checkbox" name="hurdles400" id="hurdles400"></label>

4. If your validation fails, you should return false to stop the form
from submitting:

<form ... onsubmit="return validForm(this);">

and in the function validForm():

return intHasError;

In some browsers, onsubmit returns the value of the function that it
called (i.e. relays validForm's 'false' to the form), but some
don't. Even if the function returns "false", the actual onsubmit
has been successful and so it can be argued that it should return
success (or true) even if the function returned false - unless it is
programmed explicitly to forward the returned value.

This makes sense, so you can test if the function itself worked or
not. That is, onsubmit succeeded but returned false. But it isn't
how the majority of browsers actually work (as far as I know).

5. Don't use language in your script tag, just use type:

<script type="text/javascript">

6. In your script, you have 11 document.write calls. Using an array
and join() is much more efficient:

var docContent = [
'<html><head><title>Darvans Track Program</title>',
'<style type="text/css">',
'.letterhead {text-align: center;',
' text-decoration: "bold";}',
'</style>',
'</head><body>',
'<p class="letterhead">James Darvan</p>',
'<p class="letterhead">we live somewhere</p>',
'<p class="letterhead">in some city</p><br />',
'<p>Date: frmThis.completiondate.value</p><br>',
'<p>in some city</p><br />',
'<p onclick="self.close()" style="color: blue;',
' text-decoration: underline;">Close</p>',
'</body></html>'
];

generator.document.write(docContent.join(''));
generator.document.close()

7. Don't use <a href="javascript:... > Try this:

<p onclick="self.close()" style="color: blue;
text-decoration: underline;">Close</p>

8. There are also much more efficient ways of going through your form
elements to validate the content, but I'll leave that for later.


My $0.02 worth. :p
 
A

Al Jones

<<snipped>>
2. The abbreviation for centimetre is cm, not CM. Incidentally, cm is
not an official unit of measure, but metre (m) is - but that is way
to picky for your application.
Sometimes I like picky, this particular one hit my funny bone -
measurements are to be printed in meters as well as feet and tenths of
feet <huh??>

6. In your script, you have 11 document.write calls. Using an array
and join() is much more efficient:

var docContent = [
ah, I like that - should save me some major typing when I get the
mathematics in place.
My $0.02 worth. :p
also worth at least a cuppa at some point in time. appreciate it much //al
 
A

Al Jones

'<p class="letterhead">we live somewhere</p>',
'<p class="letterhead">in some city</p><br />',
'<p>Date: frmThis.completiondate.value</p><br>', <--**
'<p>in some city</p><br />',
'<p onclick="self.close()" style="color: blue;',
' text-decoration: underline;">Close</p>',
'</body></html>'
];
Well, that was stupid, I just thought I had some idea of what I was
doing. Knowing it wouldn't work I put it in the code as a placeholder.
I've spent the last two hours on google groups to no avail - on the line
marked with the *'s how does one insert text and a form variable??
 
A

Al Jones

'<p class="letterhead">we live somewhere</p>',
'<p class="letterhead">in some city</p><br />',
'<p>Date: frmThis.completiondate.value</p><br>', <--**
'<p>in some city</p><br />',
'<p onclick="self.close()" style="color: blue;',
' text-decoration: underline;">Close</p>',
'</body></html>'
];
Well, that was stupid, I just thought I had some idea of what I was
doing. Knowing it wouldn't work I put it in the code as a placeholder.
I've spent the last two hours on google groups to no avail - on the line
marked with the *'s how does one insert text and a form variable??

I *said* it was stupid ... started cracking ebooks and one of the first
examples I see is how to do that ...

I do *not* do frustration well! Yes, I talk to myself when I'm working,
too!
 
T

Toby Inkster

RobG said:
6. In your script, you have 11 document.write calls. Using an array
and join() is much more efficient:

var docContent = [
'<html><head><title>Darvans Track Program</title>',
'<style type="text/css">',
'.letterhead {text-align: center;',
' text-decoration: "bold";}',
'</style>',
'</head><body>',
'<p class="letterhead">James Darvan</p>',
'<p class="letterhead">we live somewhere</p>',
'<p class="letterhead">in some city</p><br />',
'<p>Date: frmThis.completiondate.value</p><br>',
'<p>in some city</p><br />',
'<p onclick="self.close()" style="color: blue;',
' text-decoration: underline;">Close</p>',
'</body></html>'
];

Of course, in this particular case, that would be invalid HTML.

Ignoring the fact that HTML and XHTML syntax are mixed higglty-pigglty,
and ignoring the fact that it's missing a DOCTYPE, you have lots of '</'
strings, which are illegal in a <script>...</script> block.

If the Javascript was in an external file, then you'd only have to worry
about the mixed HTML/XHTML syntax and the lack of DOCTYPE.
 
A

Al Jones

RobG said:
6. In your script, you have 11 document.write calls. Using an array
and join() is much more efficient:

var docContent = [
'<html><head><title>Darvans Track Program</title>',
'<style type="text/css">',
'.letterhead {text-align: center;',
' text-decoration: "bold";}',
'</style>',
'</head><body>',
'<p class="letterhead">James Darvan</p>',
'<p class="letterhead">we live somewhere</p>',
'<p class="letterhead">in some city</p><br />',
'<p>Date: frmThis.completiondate.value</p><br>',
'<p>in some city</p><br />',
'<p onclick="self.close()" style="color: blue;',
' text-decoration: underline;">Close</p>',
'</body></html>'
];

Of course, in this particular case, that would be invalid HTML.

Ignoring the fact that HTML and XHTML syntax are mixed higglty-pigglty,
and ignoring the fact that it's missing a DOCTYPE, you have lots of '</'
strings, which are illegal in a <script>...</script> block.

If the Javascript was in an external file, then you'd only have to worry
about the mixed HTML/XHTML syntax and the lack of DOCTYPE.
I've been validating this all alone, helps to catch my stupidy errors, but
you're quite right, when I started to create this very dynamic piece of
code the validator threwup all over it.

The two projects that I have going are an attempt to get away from the
Dreamweaver wysiwyg that I've been doing some support stuff in.

Would you mind getting more specific on how it *should* <??> be done in
your opinion. (and that was *not* sarcasm)

Thanks //al
 
T

Toby Inkster

Al said:
Would you mind getting more specific on how it *should* <??> be done in
your opinion.

Here are two ways:

document.write('<\/p>');

or

document.write('<' + '/p>');

But the best way is to simply move the Javascript into an external file.
 
R

Richard Cornford

Toby Inkster wrote:
document.write('<\/p>');

or

document.write('<' + '/p>');
T
he former being more efficient as it completely avoids the string
concatenation that is relatively slow and heavyweight in some common
browsers (such as IE). (less bytes to download as well).
But the best way is to simply move the Javascript into
an external file.

Absolutely, and allows the users of script incapable/disabled browsers
to avoid downloading scripts that will never be executed.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top