469,916 Members | 2,562 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

onSubmit="A whole bunch of headaches"

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>

Jul 23 '05 #1
12 1503
micahl0180 wrote:
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
Jul 23 '05 #2
In article <MC0fc.17394$U83.7506@fed1read03>, micahl0180
<mi********@cox.net> wrote:
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>

type="text/javscript" is invalid
It should be type="text/javascript"

--
Dennis M. Marks
http://www.dcs-chico.com/~denmarks/
Replace domain.invalid with dcsi.net
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 23 '05 #3
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.
"micahl0180" <mi********@cox.net> wrote in message
news:MC0fc.17394$U83.7506@fed1read03...
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>

Jul 23 '05 #4
In article <MC0fc.17394$U83.7506@fed1read03>,
"micahl0180" <mi********@cox.net> wrote:
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
<script language="JavaScript" type="text/javscript">


You need to change javscript to javascript.

Here is fixed up page. See where I put in alerts to see what wasn't
going on in the code.

May not be working for over 40 hours.
Robert

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Chapter 4 - Scripting Exercise 5</title>
<SCRIPT type="text/javascript">

function diffEmail()
{
alert("in diffEmail()");
}
// Begin function to calcualte and display weekly earnings
alert("in head section");
function calcEarnings() {
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 earning
</script>

</head>
<body>
<form action="" method="post" name="payroll"
onSubmit="alert('submit');calcEarnings()">
<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>
Jul 23 '05 #5
Dennis M. Marks wrote:
<mi********@cox.net> wrote:
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>

type="text/javscript" is invalid
It should be type="text/javascript"


Also you spelled hrlypay inconsistently:

hrylpay = hrs * hrly
check = hrlypay

Try this:

function earnings() {
var totalhrs = +document.payroll.hours.value;
var hrly = +document.payroll.rate.value;
var overtime = +0;
hrs=totalhrs;
if (hrs>40) {
overtime=hrs-40;
hrs = 40;
}
var hrlypay = hrs * hrly; //pay at normal rate
var overtimepay = overtime * hrly * 1.5; //pay at overtime rate
var check = hrlypay + overtimepay;
var result='Total Hours Worked: ' + totalhrs;
result += '\nHours at Regular Pay: ' + hrs;
result += '\nHours at Overtime Pay: ' + overtime;
result += '\nRegular Pay Rate: ' + hrly;
result += '\nOvertime Pay Rate: ' + hrly * 1.5;
result += '\nPay at Regular Rate: ' + hrlypay;
result += '\nPay at Overtime Rate: ' + overtimepay;
result += '\nTotal Pay: ' + check;
alert(result);
}

MIke

Jul 23 '05 #6
In article <w81fc.109534$Ig.1719@pd7tw2no>,
Reply Via Newsgroup <re****************@please.com> wrote:

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


It took me a while to find it too.

My coding style is to always copy the script tags.

I wonder why you do not get some error message?

Robert
Jul 23 '05 #7
Robert wrote:
<snip>
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.
Jul 23 '05 #8
Richard Cornford wrote:
Robert wrote:
<snip>
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.


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

Is it a 'feature' of javascript?

randelld
Jul 23 '05 #9
Reply Via Newsgroup wrote:
<snip>
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.
Jul 23 '05 #10
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).


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

Robert
Jul 23 '05 #11
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).


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.
Jul 23 '05 #12
On Thu, 15 Apr 2004 02:08:07 +0100, "Richard Cornford"
<Ri*****@litotes.demon.co.uk> wrote:
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.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 23 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Simon Wigzell | last post: by
2 posts views Thread by gachris | last post: by
5 posts views Thread by http://links.i6networks.com | last post: by
3 posts views Thread by Aaron | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.