onSubmit="A whole bunch of headaches"

M

micahl0180

Ok, I am having trouble with the code below, but cannot seem to find the
problem. When I run it, it says Object Expected" and points me to line 31:
<form action="" method="post" name="payroll" onSubmit="earnings()">

Can anyone spot teh error in my ways. Thanks again for all your help, you
guys have been great and our making my class SOOOOOO much easier.

TIA,
ML


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Chapter 4 - Scripting Exercise 5</title>
<script language="JavaScript" type="text/javscript">
<!--
// Begin function to calcualte and display weekly earnings
function earnings() {
var hrs = document.payroll.hours.value
var hrly = document.payroll.rate.value
var overtime = 0
var check = 0
var hrlypay = 0
var overtimepay = 0
parseFloat(hrs)
parseFloat(hrly)
if (hrs > 40) {
overtime = hrs - 40
hrs = 40
}
hrylpay = hrs * hrly
overtimepay = overtime * hrly
check = hrlypay + overtimepay
alert("Total Hours Worked: " + hrs + "\nRegular Pay: " + hrs + " @ $" +
hrly + "/hour = $" + hrlypay)
}
// End function to calculate and display weekly earnings
// -->
</script>
</head>
<body>
<form action="" method="post" name="payroll" onSubmit="earnings()">
<b>How many hours did you work this week?&nbsp&nbsp</b>
<input type="text" name="hours" size="6" maxlength="3"><br>
<b>What is your hourly pay rate?&nbsp&nbsp</b>
<input type="text" name="rate" size="6" maxlength="6"><br>
<input type="submit" name="submit" value="Calculate Earnings">&nbsp&nbsp
<input type="reset" name="reset" value="Reset Form">
</form>
</body>
</html>
 
R

Reply Via Newsgroup

micahl0180 said:
Ok, I am having trouble with the code below, but cannot seem to find the
problem. When I run it, it says Object Expected" and points me to line 31:
<form action="" method="post" name="payroll" onSubmit="earnings()">

Can anyone spot teh error in my ways. Thanks again for all your help, you
guys have been great and our making my class SOOOOOO much easier.

TIA,
ML


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Chapter 4 - Scripting Exercise 5</title>
<script language="JavaScript" type="text/javscript">
<!--
// Begin function to calcualte and display weekly earnings
function earnings() {
var hrs = document.payroll.hours.value
var hrly = document.payroll.rate.value
var overtime = 0
var check = 0
var hrlypay = 0
var overtimepay = 0
parseFloat(hrs)
parseFloat(hrly)
if (hrs > 40) {
overtime = hrs - 40
hrs = 40
}
hrylpay = hrs * hrly
overtimepay = overtime * hrly
check = hrlypay + overtimepay
alert("Total Hours Worked: " + hrs + "\nRegular Pay: " + hrs + " @ $" +
hrly + "/hour = $" + hrlypay)
}
// End function to calculate and display weekly earnings
// -->
</script>
</head>
<body>
<form action="" method="post" name="payroll" onSubmit="earnings()">
<b>How many hours did you work this week?&nbsp&nbsp</b>
<input type="text" name="hours" size="6" maxlength="3"><br>
<b>What is your hourly pay rate?&nbsp&nbsp</b>
<input type="text" name="rate" size="6" maxlength="6"><br>
<input type="submit" name="submit" value="Calculate Earnings">&nbsp&nbsp
<input type="reset" name="reset" value="Reset Form">
</form>
</body>
</html>



I'm a newbie of six months and had set myself a goal of answering this
to test myself... and I got it (so I suppose we're both happy about that).
<script language="JavaScript" type="text/javscript">

You have said javscript - note, you're missing the second 'a' in
javascript thus, the tag should read:
<script language="JavaScript" type="text/javascript">


Simple but don't beat yourself over the head about it... It took me a
few minutes before I picked it up...

best of luck
randelld
 
M

micahl0180

Gentleman,

I have to thank you not only for finding the error, but for your timely
response as well. You are both truely incredible. Thank you again.
 
R

Richard Cornford

Robert wrote:
I wonder why you do not get some error message?

Because the browser's reaction to being presented with script tags
specifying a script language that it doesn't understand/implement is not
to attempt to execute it (it cannot decide that text/javscript isn't a
real script language, because it might be). And a script that is never
run cannot error.

Richard.
 
R

Reply Via Newsgroup

Richard said:
Robert wrote:



Because the browser's reaction to being presented with script tags
specifying a script language that it doesn't understand/implement is not
to attempt to execute it (it cannot decide that text/javscript isn't a
real script language, because it might be). And a script that is never
run cannot error.

Richard.

But it did error - One gets "Object Expected"...

Is it a 'feature' of javascript?

randelld
 
R

Richard Cornford

Reply Via Newsgroup wrote:
But it did error - One gets "Object Expected"...

Is it a 'feature' of javascript?

The event handling attribute function errored because it could not find
the function that it was trying to call (because it had been specified
in an unknown scripting language and so not instantiated). The event
handling attribute code is not influenced by the type attribute
assignments of any script elements (except on IE, where they default to
the language of the first script element encountered, or JScript if
there is no separate script element, though the W3C have a different
idea about how the language for intrinsic events should be defaulted).

Richard.
 
R

Richard Cornford

Robert said:
Couldn't is say it doesn't have an interpreter or plugin for
javscript?

Would you really want to be told every time you loaded a page that
contained any VBScript? Would such a warning provide any value to the
bulk of browser users?

Scripting is supposed to be an optional extra, and possible in any
language (though nobody seems interested in implementing any language
but ECMAScirpt, except Microsoft) so quietly ignoring anything that
cannot be used is the logical (and specified) reaction.

Richard.
 
J

Jim Ley

though the W3C have a different
idea about how the language for intrinsic events should be defaulted).

but it didn't have 2 independant implementations when it went to REC,
is badly specified*, so I think we should ignore it, avoiding all
intrinsic events would be better than using that awful hack.

Jim.

* Meaning of course that it should never have got to REC but the W3
used to ignore their own process documents, they're getting much
better, but keep an eye on them - the HTML WG are also the worst IMO.
 

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

No members online now.

Forum statistics

Threads
473,786
Messages
2,569,626
Members
45,328
Latest member
66Teonna9

Latest Threads

Top